Switching from Selenium to Playwright

Switching from Selenium to Playwright

Johannes Zelger is the CTO of Finidy and developer of innovative ESOP software solutions.

Switching from Selenium to Playwright: Why We Made the Leap

End-to-end (E2E) testing is a crucial part of ensuring quality in modern web applications. For years, we relied on Selenium as our go-to framework. While Selenium is a powerhouse, we recently decided to switch to Playwright for our E2E testing needs. This wasn’t a decision we took lightly, but after seeing the benefits Playwright offers, it became clear that this was the right move. Here’s why we made the switch and the advantages we’ve experienced so far.

Key Advantages of Playwright

Effortless Parallelism

Running tests in parallel is vital for speeding up feedback loops, especially during local development. While achieving parallelism in Selenium often required additional configuration and infrastructure setup with Selenium Grid, Playwright makes it almost effortless. With built-in support for parallel execution, we saw immediate performance improvements with minimal effort.

Built-in Smart Waiting

One of the standout features of Playwright is its built-in mechanisms for waiting. Unlike Selenium, where explicit waits or custom retry logic were often necessary, Playwright automatically waits for elements to become visible or actionable. This drastically reduces the chances of flaky tests caused by timing issues.

Automatic Retries

Playwright offers automatic retrying of failed tests, making it easier to identify and fix issues. Instead of re-running entire test suites manually, Playwright retries just the failed tests, saving time and effort during debugging.

Cross-Browser Testing

Out of the box, Playwright supports modern browsers like Chromium, Firefox, and WebKit. Its ability to run the same tests across these browsers with consistency is a game-changer for ensuring cross-browser compatibility.

Headless and Headed Modes Playwright makes it easy to switch between headless and headed modes. This is particularly helpful during debugging when you want to visually observe the tests while maintaining fast execution in CI environments.

Powerful Debugging Tools

Playwright comes with powerful debugging tools like Playwright Inspector, which allows you to step through each test action and examine the state of your application in real-time. This has been a massive time-saver for our team.

Rich API

Playwright’s API feels modern and developer-friendly. From handling file uploads to intercepting network requests, Playwright provides robust tools that often required additional libraries or workarounds in Selenium.

Consistency and Reliability

With its emphasis on deterministic test execution, Playwright minimizes the risk of flaky tests. This has been a big win for us, as it boosts confidence in our test results.

Why Playwright Works for Us

Switching to Playwright has improved our testing workflow significantly. The built-in tools and features allow our developers to focus on writing meaningful tests instead of dealing with the framework’s limitations. Additionally, Playwright’s strong community support and regular updates ensure that we’re always equipped with the latest tools for our testing needs.

We ware able to cut down on test execution time, reduce flakiness, and improve the overall quality of our E2E tests. The execution time was cut down by more than 50% without parallelism on our CI.

Final Thoughts

While Selenium served us well for many years, Playwright has elevated our testing game. If you’re considering making the switch, we highly recommend giving it a try. Whether you’re looking for better parallelism, less flakiness, or easier debugging, Playwright delivers on all fronts.