Skip to main content

Command Palette

Search for a command to run...

Cypress vs Playwright: Which is best for E2E testing?

Updated
โ€ข3 min read
Cypress vs Playwright: Which is best for E2E testing?

Cypress was our go-to end-to-end (E2E) testing tool, and we were pretty happy with it, up until recently that is. Lately, we've run into a couple of testing scenarios where Cypress support has been limited, notably around multiple domains/tabs and iFrames. This caused us to re-evaluate the available E2E tools and it ultimately came down to two options; keep Cypress or switch to Playwright.

In this article, I compare both tools in the format of an ADR, which should help us decide which tool to go with. Let the battle commence!

Cypress

https://www.cypress.io/

  • Good, because it's very easy to learn and get set up with basic tests.

  • Good, because it has a nice dashboard to view test reports, analytics and recordings.

  • Good, because it supports Chromium and Firefox.

  • Good, because it has a very slick Test Runner UI.

  • Good, because it's built specifically for end-to-end testing.

  • Good, because you can edit your test code in the browser and instantly see it run as you change the code.

  • Good, because it's mature and has good community support.

  • Bad, because it doesn't support multiple domains.

  • Bad, because authentication requires a lot more setup due to lack of multi-domain support.

  • Bad, because it doesn't support Webkit (Safari)

  • Bad, because you cannot run tests against multiple browsers at the same time.

  • Bad, because iFrame support is limited.

  • Bad, because there is no "hover" support.

  • Bad, because the chaining command syntax can quickly get out of hand for more complex tests.

  • Bad, because you have to pay a premium to get access to some dashboard features (e.g flake detection)

  • Bad, because to do parallelization well, it requires vendor-locked software.

Playwright

https://playwright.dev/

  • Good, because it supports Chromium, Firefox and Webkit (Safari).

  • Good, because it supports multiple domains and tabs.

  • Good, because it supports 5 language bindings (Javascript, Typescript, Java, Python, .NET)

  • Good, because it's fast.

  • Good, because you can run tests against multiple browsers at the same time.

  • Good, because it fully supports parallelization, even locally.

  • Good, because it supports parallel tests within a single test file.

  • Good, because it's Javascript first, so feels more natural.

  • Good, because it has "hover" support.

  • Good, because iFrames are natively supported.

  • Good, because it supports reuse of authentication state to speed up tests.

  • Good, because it lets you choose your test runner (e.g. Jest but the default one is advised)

  • Good, because signing in is simple, you just fill in the form.

  • Good, because it's completely free.

  • Good, because it has few dependencies.

  • Bad, because it's still quite new, so possibility of a smaller community.

  • Bad, because 3rd party tutorials are out of date due to changing API.

  • Bad, because it's a mix between an automation and testing framework.

  • Bad, because it has a steeper learning curve.

  • Bad, because it does not have a dedicated dashboard so would be harder to debug tests remotely.

Common features between both

  • Good documentation

  • API testing

  • Point & click test recording

  • Test debugging tools

  • Test retries

  • Automatic waiting

  • Video and screen capture

  • Mobile emulation

  • Regularly updated and well maintained

  • Run only a subset of tests

  • Network monitoring

Conclusion

In the end, we decided to go with Playwright, mainly because of its native support for multiple domains, tabs and iFrames. I will say that I found Cypress' debugging to be more developer-friendly and in general "slicker", but that wasn't enough to make us stay put.

Want to see more?

I mainly write about real tech topics I face in my everyday life as a Frontend Developer. If this appeals to you then feel free to follow me on BlueSky. ๐Ÿฆ‹

Bye for now ๐Ÿ‘‹

H
hiroyone4y ago

Hi Cathal,

Thank you for sharing your thought. This is great!

It seems your team was originally using Cypress but switched to Playwright in the middle. Can you teach me the way you guys migrated and the amount of effort it took?

My team is also currently using Cypress for our enterprise project but cannot imagine the switching path.

Regards,

1
C

Hey hiroyone, thanks for reading!

Thankfully we didn't have a whole lot of tests to convert (maybe 3 test files) so it was really quite easy. I can imagine how difficult it could be if you have a large test suite. We simply looked at each test in Cypress and mimicked the steps in Playwright. For example:

  1. Go to x domain
  2. Click y button
  3. Check the z page is now displayed

Of course, the API and syntax is different so the first thing to do is to learn how to write tests in Playwright via their docs, you'll then be a lot more comfortable when migrating.

Also, there's no need to convert all Cypress tests right away, it's perfectly fine to have both Cypress and Playwright live alongside for a while and migrate one test file at a time. You'll really start to see how much more robust Playwright is.

I just published this article which you can look to for some tips and best practices: https://cathalmacdonnacha.com/playwright-e2e-testing-tips-and-best-practices

Hope that helps!

H
hiroyone4y ago

Cathal Mac Donnacha

Thank you so much for your quick and detailed response.

Thankfully we didn't have a whole lot of tests to convert (maybe 3 test files)

My team has around 10 files and all of them are somewhat heavy.

Also, there's no need to convert all Cypress tests right away You absolutely made a good point. I will keep this in mind.

Another team of my company decided to go with Playwright, and we will examine which project goes better in scale.

I just published this article which you can look to for some tips and best practices: cathalmacdonnacha.com/playwright-e2e-testin..

Looks great! I will read the post throughly.

Best,

1
C

hiroyone Best of luck ๐Ÿ‘