Cypress, I’m having an affair with Playwright.
27 May 2022
I assume! I am flirting with Playwright despite having had a long and happy relationship with Cypress.
More important than developing a web application is to make sure it works as intended. And this is where automated testing frameworks come into play. In this article we’re going to compare Cypress, one of the most well-known automated tests framework, to the new kid on the block: Playwright.
What is Cypress?
Cypress is an open-source automated test framework that allows developers and QAs to write e2e, integration or unit tests. Thanks to its Test Runner UI it is very easy to understand why tests are failing. Also, thanks to the user-friendly API it has a tiny learning curve even for people that are not used to writing code every day. It was a huge improvement to the previous most used tools (like Selenium) mostly because of the simple setup without the need to install other dependencies.
And, for quite some time, despite its limitations, Cypress remained the preferable framework for most developers and software houses…
… until Playwright joined the show. And competition is good for business.
What is Playwright?
Playwright is also an open-source framework but is maintained and developed by Microsoft and was primarily created because there was a gap in the ability to run automated tests across multiple browsers (Cypress does not support Safari). Another great feature of Playwright is that it supports running parallel tests on a single machine both locally and on CI.
So why am I considering jumping into the Playwright train despite having been a fan of Cypress for many years? The answer is simple. Cypress has some crucial limitations:
- No Safari support: This is a big issue because we don’t want our application to only work in Chrome and Firefox. Although Chrome makes up for the most users, Safari is widely used, and we can’t just trust that it will work (because everyone knows that web applications don’t run on trust)
- Parallel running of tests: If you want this in Cypress you have to subscribe to their parallel execution service and you have to run the tests on multiple machines. You can do it in a single machine but even Cypress does not recommend this.
There are some other disadvantages. Since Cypress is an electron app that embeds a browser and its instructions are directly injected in the event loop of that browser, it is limited only to javascript and other transpiled languages. Playwright, on the other hand, uses Chrome DevTools Protocol (CDP) which allows automation to be done directly on the browser.
Another big disadvantage for Cypress is that working with iframes is… difficult (as you can see on Cypress’ own blog!)
Playwright fully supports async/await syntax (which I personally prefer) and Cypress uses a promise-based syntax.
On the other hand, Cypress benefits from its community. Since it is a mature project, it is very easy to find someone who can help. Playwright is relatively new so the community is smaller, and some information found online can be deprecated due to API changes.
Both frameworks have complete and reader-friendly documentation (bonus points here for Cypress due to larger community), have screen record capabilities, can emulate mobile, network monitoring and test retries.
So, which one is better?
Well… it is complicated. I can’t tell you that X framework is better than Y because, as always, it boils down to what are the needs of your project and team, but a nearshore team can help you decide.
If Safari support is crucial to your project, or if you have a lot of tests and parallelization is important, then Playwright is the best option for you.
If your team is somewhat inexperienced concerning tests, and you require a user-friendly/practical library and a more stable framework which comes with a wide support community, then Cypress is the framework for you.
Personally, If I had to choose one of these frameworks, I would go for Playwright. Simple and free parallelization, multiple languages support, async/await syntax and Safari support are great selling points. Even though I had fallen in love with Cypress in the past, our relationship lost its spark and I’m ready to find a new love…
At craftable, we take all these points and try to match them to the requirements of the projects and the needs of the team. Every case is a different case and that’s why boutique software can be the best solution, because more than anything else, we aim to make the best choices for each specific situation.
For more content like this, explore craftable’s website and visit us on Medium, Twitter, or LinkedIn.
Cypress, I’m having an affair with Playwright. was originally published in craftable on Medium, where people are continuing the conversation by highlighting and responding to this story.