Skip to content

25 July 2023

Uncovering the ultimate Test Automation tool

logo
Faizan Ahmad

A Comparative Study of Playwright and Selenium

As a seasoned Test Engineer with a few years of experience under my belt, I have had the privilege of working with a variety of technologies and tools. One of my favourites among these was Selenium, which I used extensively in my previous roles. I have always been a big fan of Selenium and its capabilities as a test automation framework.

When I first joined Hippo, I was tasked with a project that involved transitioning from Selenium to Playwright. This presented me with a unique opportunity to delve deeper into Playwright and expand my skill set.

With my hands-on experience with both Selenium and Playwright, I feel well-equipped to compare the two tools and make an informed decision about which one is the better option.

If you are on the lookout for a reliable test automation tool and are torn between Selenium and Playwright, then this comparison will provide you with valuable insights that will help you make an informed choice.

But before jumping into comparison let’s look at the tools individually.

What is Selenium?

Selenium is an open-source web automation tool that has been available on the market since 2002. The framework has the ability to automate, manage web browsers, and communicate with UI elements.

It is the industry’s most widely used framework by a wide margin with the following tools making up the Selenium suite:

  • Selenium Webdriver – a collection of open-source APIs that can be utilised while testing web applications to verify if they are working as expected.
  • Selenium IDE – used to record user interactions on the browser and can be reused again which makes it easy to use for non-technical users or manual testers.
  • Selenium Grid – allows running multiple tests across different browsers, browsers versions and operating systems. Although I have not personally used it, it is great to test applications whose users can be of a wide range.

Selenium uses the Webdriver API between drivers and browsers. For each Selenium command, respective JSON is created which is sent to the browser which returns the HTTP response. The response is sent back to IDE using the same protocol.

What is Playwright?

A nodeJS library released by Microsoft aimed at automating End-to-End testing of web applications.

Playwright does support multiple browsers, platforms and languages but fewer in comparison with Selenium.

It by default launches the headless browser and has many helpful features like auto waiting of elements and automatically retrying for checks in assertions.

The latest version at the point of writing this article is 1.36 although it is currently actively developed by Microsoft meaning it is being developed while considering modern web applications and new features with every new update.

Playwright uses a WebSocket connection to communicate with browsers which stays open during the test execution. One of the reasons for the Playwright’s speedy execution is sending and receiving data from IDE to the browser and vice-versa in one connection stream.

Selenium vs. Playwright

Now we have basic background information on the two tools. Let us look at them side by side.

Both web automation testing tools, Playwright and Selenium are open source and support cross-language, cross-platform and multiple browsers. Both tools also support CI/CD via Jenkins and Azure.

To produce a specific comparisons, we’ll assign a score to each tool based on the parameters below. In the end, the tool with the highest score will be our winner.

Language support

Playwright supports Javascript/Typescript, Java, Python and C# while Selenium supports Python, Java, JavaScript, C#, Ruby, Php, and Perl.

Score

In my case, the project is developed using C# and I have experience coding in both C# and Java so I could use either tool. I will give one point to each. You can decide yours depending on the tech stack of the project and your personal preference for the language.

Playwright – 1, Selenium – 1.

Multi-browser support

Playwright supports Firefox, Chromium, Google Chrome, Webkit, Microsoft Edge and BrowserStack support while Selenium supports Google Chrome, Opera, Safari, Microsoft Edge, BrowserStack support, and IE.

Score

I had set browser requirements for the project and both tools support those browsers. One point to each again.

Playwright – 2, Selenium – 2.

Operating System Support

Playwright supports Windows, Mac OS and Linux while Selenium supports Windows, Mac OS, Linux and Solaris.

Score

I have been working on mac OS and both tools support these so one point for each again.

Playwright – 3, Selenium – 3.

Wait

Playwright comes with native wait making testing more resilient and removing flaky tests while in Selenium you have to add implicit, explicit, and fluent waits.

Score

For this reason, I want to give Playwright 10 points as it has made my life very easy. But to be consistent on the pre-determined ratings, Playwright scores one point.

Playwright – 4, Selenium – 3.

Community Support

Since Playwright is new to the industry, it has a small community which is growing rapidly while Selenium has large, established documentation and support options available.

Score

Now the question we need to ask ourselves is does the existence of a wider community matter to you?

Having a community to reach out to is incredibly beneficial for me. It doesn’t necessarily need to be a large one; as long as I can find solutions to my problems, a small community works just fine. I would give a score of one to each tool in this case.

Playwright – 5, Selenium – 4.

Screenshots

In Playwright, integrated screenshots of full page and individual elements are available. It also has the option to put screenshots in a buffer, trace viewer – GUI tool which allows you to playback traces. On the other hand, in Selenium users have to use the “TakesScreenshot” interface.

Score

Both tools do the job but Playwright wins because the trace viewer is quite helpful and easy to implement.

Playwright – 6, Selenium – 4.

Video Recording

Playwright allows video recording using browser context where you can specify directory and size while Selenium does not have direct video recording available.

Score

Although at this stage video recording is not a requirement in this specific project, it is better to have it so I will give Playwright another point.

Playwright – 7, Selenium – 4.

Multiple Pages and Tabs

Playwright allows having multiple pages and tabs in one browserContext and each behaves as active. By contrast, Selenium has to switch to tabs and pages before interaction which makes it a bit more complex. Playwright scores the point again for simplicity.

Score

Playwright – 8, Selenium – 4.

Popup Handlings

Playwright automatically dismisses the popup and alerts and also allows the functionality to handle them if required while in Selenium pop-ups need to be addressed.

Again for simplicity, Playwright has scored for me.

Score

Playwright – 9, Selenium – 4.

Reporting

Playwright has built-in reporting available while in Selenium, external reporting can be integrated through software such as Allure Extent Reports.

Score

Playwright – 10, Selenium – 4.

Real devices and mobile testing

In Playwright, no support for real devices is available but there is experimental support for android automation. Real devices and mobile testing can be done via BrowserStack while Selenium supports real device cloud mobile testing using Appium.

Score

Is this a project requirement to have real device testing? In my case no but I will still give Selenium the point for having this feature.

Playwright – 10, Selenium – 5.

Conclusion

Depending on the requirements of your testing you can also ask yourself these questions to help you decide.

Do you need to consider test execution speed?

Does writing longer pieces of code matter to you?

Looking at the final scores, Playwright has won by a difference of 5 points.

For the time that Selenium has been around, it has been a great tool for carrying out test automation projects, and it has a community that helps a lot to solve any problem.

But after using Playwright, I was blown away by its simplicity and speed.

In my opinion, Playwright is quickly rising to the top as the go-to tool for test automation. Based on my experience, the ease of use and rapid execution make it a game-changer in the industry.

Many forward-thinking organisations have already made the switch to Playwright, recognising the potential it holds for streamlining their testing processes.

Whether you’re just starting your automation journey or looking to upgrade your existing toolkit, it’s crucial to take a step back and assess your needs.

I highly encourage you to do your research and explore your options, but for me, the choice is clear: Playwright is the winner. The combination of speed, power, and accessibility make it a standout choice for any automation project.