Selenium vs Playwright – A short comparison

We all know that automation testing has become an integral part of software development and the choice of the right automation tool can make a significant impact on the overall efficiency and effectiveness of the testing process. Given this, there are a few tools that comes to mind, like Selenium, Cypress or Playwright, with Selenium being the most popular and widely used. 

However, Playwright is gaining popularity fast and it’s worth taking a closer look at what it can do and how it compares to Selenium.

But first, a little bit of history. 

What is Selenium and how long it’s been around?

Selenium has a long history of running as an open source tool for browser automation, being initially developed in 2004 by Jason Huggins, and since then it has received constant updates and new features. Selenium is a very popular and widely-used tool with a huge community of users to support. 

This framework can automate and control web browsers, by interacting with the UI elements, and it’s components are:

  • Selenium WebDriver: It’s a web framework, with a collection of open source APIs used to test and verify web applications easily. This requires coding knowledge and it’s not as easy to use as Selenium IDE
  • Selenium IDE: This is a record & play tool, which basically records all your actions on a web page and automatically creates a test, which you can run later on
  • Selenium Grid: Enables the user to distribute and run tests in parallel on multiple machines

As we were saying, Selenium has been receiving constantly new updates and fixes, and recently they released Selenium 4, with a bunch of cool features, which I detailed in this article.

What is Playwright and why we compare it with such a legendary tool like Selenium?

Playwright is kinda new, open source, like Selenium, tool for automating browsers, and it’s first version was released by Microsoft in 2020. The team behind this tool is the same behind Puppeteer, a testing framework designed to work headless for Chrome / Chromium. But the team realised the limitations of this and decided to go beyond and offer support for multiple browsers and other good changes, through Playwright.

Like Selenium, Playwright is designed for end-to-end automated testing of web applications. It is cross-platform, cross-browser and cross-language and on top of Selenium, it has a cool feature auto-waiting, among other things. No matter you are testing a simple or complex projects, you’ll see that Playwright was designed to reduce flakiness, increase tests running speed and make maintenance easier. But stick with me, we’ll see why in a bit.

Playwright & Selenium Architectures

First, let’s have a look at each of these tool architectures. Playwright works directly with the WebSocket. What does this mean? Well, once you run / trigger the test, the code is converted into JSON format and it is sent to the server using WebSocket protocol. Once the connection is done, commands are send between your tests and the Playwright server. 

Client and server connections remains active until one or both parties cancel them, which is one of the reasons Playwright is fast, because the connection stays active. 

Up until recently, Selenium was using the JSON Wire Protocol. But since the Selenium 4 was released, they removed the JSON Wire Protocol in favor of W3C Webdriver Protocol, which became the official standard for controlling web browsers. The new protocol is called simply Webdriver W3C and what’s new is that now, we can see direct communication between the client and the server, without the need of JSON Wire Protocol. 

Below you can see the old Selenium architecture:

and the new architecture Selenium 4 uses:

The new architecture improves test running speeds a bit for Selenium too, and also the Actions API has been revamped, allowing you to perform multi-touch actions, zoom-in, zoom-out and more.

Installation and Configuration

We are going to use Intellij IDEA as an IDE for the following examples and screenshots. Both Selenium & Playwright can be easily installed and configured via a Maven project, by adding the correct dependencies in the pom.xml file:








Browser support

Both Playwright and Selenium offers a wide range of browsers to run your automated tests. Playwright offers support for Chromium, Firefox and WebKit, while Selenium offers support for Chrome, Firefox, IE, Edge, Opera and Safari. By far, there is a clear winner here, with Selenium offering a wider range of supported browsers.

Test runner frameworks

Playwright offers support for Mocha, Vitest, AVA and Jest / Jasmine, while Selenium offers support for TestNG, JUnit, Mocha, WebDriver IO, Protractor and more. One interesting note here is that Playwright can be configured to run with TestNG too, and you can find more details here.

Other details

Both are open source and free, but Selenium being the oldest in the room, it is backed by it’s larger community and you’ll find support / solutions more easily. But Playwright has a good documentation and it’s gaining more and more popularity, so I believe it’s just a matter of time until Playwright will have a strong community to. 

Another thing to consider is that Playwright can offer only native mobile emulation right now, compared to Selenium, which can offer support for real devices. But with the help of third party apps, such as Browserstack or LambdaTest, you can integrate Playwright tests to run on real devices too.

In terms of performance, due to it’s headless browser with event-driven architecture, Playwright wins by far. But you don’t have to trust me, the team behind Applitools made a battle and here you can watch the results:

What’s going to be? Selenium or Playwright?

There is no easy answer to this question. Both have their advantages and disadvantages, and it’s important to analyze and understand the requirements on the project. After this, you can develop a POC and see what tool will best suite you and your team. 

Until next time, happy testing & coding! 🙂

Previous post Next post

Step-by-Step Guide: Setting Up Cypress & Testing Login

Read More

Playwright with TestNG+bonus QMetry Integration

Read More

Comments are closed.