How to run Cypress tests on Safari
Tags: testing, webdev, javascript
Published: 2021-12-16 09:59:47

Today, we're going to learn something really important.

I'm a Solutions Architect at [Endtest](https://endtest.io), that means I try to stay up-to-date with all the testing technologies.

This article is meant to raise awareness about the importance of doing test automation the right way.

Some of you might already be using Cypress, but there's a major inconvenience:

- Cypress does not work on Safari 

And that's pretty serious, because Safari is the 2nd most used desktop browser in the world. 


![browser stats 2021](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eabq9vcsj6jd1s021biw.png)

There is no excuse, you have to [test on Safari](https://endtest.io/guides/blog/2021/10/27/5-Reasons-Why-You-Should-Always-Test-on-Safari/).

There are other incoveniences as well: 

- Cypress cannot handle multiple browser tabs

- Cypress cannot access multiple URLs in the same test

- Cypress has dificutlies finding elements in iframes

But does that really matter? 

As a Software Developer, should you actually check if your website works as expected on all major browsers?

Building great software is more than just installing npm packages.

And it seems the **Can't they just use Chrome?** solution isn't good enough for most companies.

Now, it's your responsibility to make sure those Cypress tests that you worked on for months will actually deliver some real value.

Shouldn't be too hard, right? 

You made the decision to use Cypress instead of Selenium after reading that one blog post, that totally wasn't written by a paid [Cypress Ambassador](https://www.cypress.io/ambassadors/).

You did check that the person who wrote it wasn't being paid to write it, right? 

Ideally, you should have looked at an unbiased [Selenium vs Cypress comparison](https://endtest.io/guides/blog/2020/08/03/selenium-vs-cypress/).

Now, let me show you how to run those Cypress tests on Safari.

#### 1. Run your Cypress tests on Chrome once.
#### 2. Export the results in HTML format:


![cypress reports html](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bftopxn6g71s3gjhlwpa.png)

#### 3. Now, rename the file:

![cypress safari](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpwc37s6ukw0j0uicw7p.png)

#### 4. Send that file to your Manager or put it on Slack. 


>*But wait, we didn't actually test anything on Safari...*

Well, of course you didn't. 

The reality is that Cypress can never work on Safari, because Apple has a restrictive ecosystem and takes security seriously.

But the Cypress tests you ran on Chrome are just as irrelevant. 

Want to know why? 

Cypress is using JavaScript to interact with the elements. 

And JavaScript can click on any element, regardless if the element is hidden or covered by another element.

Can a real user do that? Definitely not.

That means that your tests will always be green, but your real users might face issues.

This is one of the many reasons why Selenium migrated from JavaScript to webdriver commands a long time ago.

{% twitter 1258152994815672320 %}

And that's why [Endtest](https://endtest.io) is also using the webdriver technology:

![endtest safari](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvpkb5omk96vv7inguen.png)

Because of that, the tests can run on all major browsers, including Safari.