DEV Community

Cover image for How to run Cypress tests on Safari
Liviu Lupei
Liviu Lupei

Posted on

How to run Cypress tests on Safari

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

I'm a Solutions Architect at Endtest, 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

There is no excuse, you have to 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.

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.

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

3. Now, rename the file:

cypress safari

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.

And that's why Endtest is also using the webdriver technology:

endtest safari

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

Top comments (0)