Playwright versus Cypress
Tags: e2e, playwright, webdev, cypress
Published: 2022-12-08 09:00:58

I was seeing a lot of Playwright mentions in my timelines recently, so I decided to investigate what the fuss was all about. Playwright, as it turns out, is a tool for executing end to end (e2e) tests, similar to Cypress.

With Cypress being my go to tool to integrate e2e tests, I figured I could do a comparison on the two, to see which better fits my needs at this point.

I want to stress that both tools are very good at what they do, apart from edge case scenario’s I don’t see a direct need to migrate existing projects from one to the other.

Having said that, let’s talk about end to end testing. If you are working on complex applications it becomes increasingly difficult to maintain quality in existing features. Introducing a change that affects an existing feature is commonly known as a “regression bug” and you want to avoid it at all cost!

Before the dawn of automated tools, these type of tests were done by hand, by a human tester which had to navigate entire flows and screens to assess whether all of the normal flows and edge cases were still functioning. You can imagine the scale of these tasks!

Enter automated e2e tests. As a developer or tester, you can write and automate these tasks ([and as we know, you should](https://www.joranquinten.nl/articles/everything-repetitive-should-be-automated/)!) so you that the entire test suite of features can do the heavy lifting for you, without losing concentration or human error.

## Similarities

Having done a quick side by side comparison, the similarities are most obvious. Cypress and Playwright both automate the testing for you and integrate nicely with your development flow. Since they’re both JavaScript based, the language and selectors are very familiar to developers. Although Cypress is a bit more of it’s own flavour of selecting, nothing to fret about honestly.

Both of the frameworks are open source packages which you can easily install on your projects and execute in any pipeline, in a visual interface or from a terminal. They both offer component testing, feature testing, screenshotting, adjusting the viewport in different mainstream browsers (Playwright offers Webkit). Both have forsaken ie11, which is something we shouldn’t even address anymore these days (the hurt is still there 😢).

Bottom line is that basically they both offer similar capabilities with minor differences. The support for Webkit by Playwright might be a deal maker for some, depending on the investment in 100% cross browser quality assurance.

## Differences

So can we try and spot some differences? It’s the little things where Playwright is a bit more optimised for delivery. It has a bit of a larger package size than Cypress (expanding with adding more browsers), but has less dependencies as a whole. Fewer dependencies means slightly quicker installs in an automated runner.

Playwright also uses the `async` `await` pattern when it comes to assertions, rather than what Cypress does in terms of retrying assertions. Playwright also allows you to run several browsers concurrently, which potentially saves heaps of time depending on the coverage you’re after.

And there’s one other thing that Playwright does really well, and that’s supporting multiple pages and domains and setting contexts. This is very useful when dealing with third party features that are part of your flow (dealing with popups, iframes and such).

These differences to me indicate to me that Playwright will scale very well in bigger setups that what I’ve been trying out for now, since a lot of these small decisions amount (especially over time and at scale) to shorter duration of executing the test suite.

## A verdict?

Again, for general or small to mid scale usage, Cypress is just fine. Especially if you already have your test suites up and running (I think it’s reasonable to expect more changes coming the Cypress in the future too).

On the other hand, if you’re either starting a new project or haven’t invested a lot yet in setting up your tests, or if you are working on large scale projects, I’d put my money on Playwright. It seems to be specifically tailored to address the pain points that you’d have on larger scales, where every extra second of run time amounts to big numbers at scale.

While the documentation and community of Playwright is emerging, you can expect it to grow as well and with the support of Microsoft on the product you know it has a solid foundation as well.