Playwright has become the test automation framework of choice for many software development teams for good reason. In this article we’ll look at the main advantages – and disadvantages – of using Playwright in the real world.
Advantages of Playwright
1) Automatic Waits
One of the biggest problems with test automation is flaky tests, and this affects Selenium in particular. With Selenium you have to spend a significant amount of time when creating tests to ensure that the tests wait for elements to be visible, or clickable. And even if you think you’ve successfully achieved that when writing them, when they execute in a pipeline they may still fail occasionally because the waits you’ve set up don’t always work in a different environment.
Playwright solves this (mostly) by using automatic built-in waits, making the tests easier to write and more stable when executed. There are still occasions when waits have to be customised in Playwright, but they are much fewer.
For me this is a HUGE benefit and this advantage alone makes Playwright the framework I like to use.
2) Cross Platform Support
Although Selenium can be used with all the main languages like Typescript / Javascript, Java and C#, Cypress can only be used with Typescript / Javascript.
3) Comprehensive Tooling
When using a different test automation framework, you may have to also select, install and integrate a separate test runner such as NUnit or MSTest, an assertion framework such as Jasmine or Mocha, a separate reporting tool such as TestNG or Allure, and a third party visual testing tool. Playwright has it’s own built-in versions of all of these tools so is much easier to install and they are more integrated.
4) Visual Studio Code Extensions
There is a Playwright plugin for Visual Studio Code which provides a lot of functionality to help when writing automated tests. Other IDEs may also have similar aids, however the VS Code one is frequently updated with new versions.
5) Browser Version Support
One of the headaches with Selenium was downloading and maintaining the correct versions of browser drivers, especially making sure the same versions were used when creating tests locally and in the CI/CD pipeline. Playwright solves this problem by taking over management of the browser drivers.
Disadvantages of Playwright
1) Asynchronous Code
Most test automation frameworks are moving to using the asynchronous coding style so this will apply eventually to them all, so you’ll have to get to grips with it sooner or later! Unfortunately in my opinion asynchronous code offers few, if any, benefits to test automation and can cause problems for less experienced test automation engineers. Fortunately IDEs are providing better support to asynchronous coding and increasingly help overcome the issues it creates.
2) Documentation
In my opinion the documentation provided by the official Playwright website is confusing to navigate and understand, particularly for learners or people moving from manual testing. Additionally, the contributions in Stack Overflow are often unhelpful because they refer to older versions of Playwright which are quite different, and so in general I haven’t found Stack Overflow as helpful as it has been in the past with Selenium or coding in general. Both of these resources should hopefully improve in time.
3) Complexity and Versatility
Compared to Selenium in particular, which is a simple and easy to understand framework, Playwright can seem overly complicated at times, with many ways to do the same thing. Consequently it’s much more difficult to master. It also leads test architects to implement very cool complicated test frameworks for your project which can be a nightmare for everyone else to work with. C’mon guys, test automation is not rocket science: Keep It Simple Stupid! (KISS)
Overall
I hope this article has shown some of the advantages and disadvantages to using Playwright compared to Selenium and Cypress.
Overall I prefer to use Playwright over these others, mainly because of the huge benefit of the automatic waits. It not only makes tests easier to write but more importantly it makes them more robust and less flaky across the development and pipeline environments. Just remember to KISS!