Playwright vs Selenium Comparison | Why Should You Choose Playwright
This tutorial on Playwright vs Selenium will explore why Selenium which has been a ruler for decades is facing a new challenge from a fairly new competitor called Playwright.
If you have been working with Selenium for a really long time, you are already aware of the limitations that you had to face. Or maybe you were forced to write longer codes in order to reach smaller goals.
This tutorial will do a step-by-step comparison between the two and let you know why one is better than the other.
I would try to leave an open verdict by the end but then again the reason I bumped into Playwright is because of its simplicity and the way it tackles the limitations that we had faced over the years working with Selenium and other Frameworks.
Playwright vs Selenium
Let us start off with the basics of what these are. Shall we?
What is Playwright?
Playwright is a free open-source framework for Web Testing and Automation developed by Microsoft. Created by the same team who created Puppeteer.
- It allows testing Chromium, Firefox, and Webkit with a single API.
- Has been built to enable cross-browser web automation that is ever growing, simple, fast, and reliable.
- The first release happened around 2020.
- More than 236 contributors.
The following companies use Playwright:
You can get started with it almost immediately.
What is Selenium?
Selenium is a free open-source framework that automates web applications. Provides a single interface to let you write test scripts in multiple languages.
- Was launched in 2004.
- 635+ contributors.
- Recent release: Selenium 4.0.
The following companies are believed to use Selenium:
Let us move on to the next section that will do a side by side comparison between the two:
Playwright vs Selenium Side by Side Comparison
Playwright
- Languages supported: JavaScript / TypeScript, Java, Python, C#
- Multi-Browser support: Chromium, Firefox, Webkit, Chrome, Edge
- Installation: Only NodeJS needs to be installed. Seamless Installation.
- Architecture: Headless Browser with event-driven architecture
- Wait: Comes with native wait which makes testing more resilient – No flaky tests!
- Page Object Model can be implemented
- Dynamic Assertions with auto retry functionality
- Screenshots: Integrated screenshots of full page, individual elements, and options to put screenshots in a buffer. Image format, quality, and specific area selection.
- Video Recording: using browser context where you can specify dir, size, etc.
- Multiple Pages and Tabs: Run tests across (No bringing the page in front is required)
- Handling Popups is very easy using popup event listeners
- API Automation: In-built API support. No need to install separate packages.
- Reporting: In house reporting is available
- Less support as compared to Selenium since Playwright is fairly new.
- Real devices are not supported, only emulators.
- Mobile Testing: Experimental support for Android automation (Chrome for Android and Android WebView)
Selenium
- Languages supported: Python, Java, JavaScript, C#, Ruby, Php.
- Multi-browser support: Chrome, Firefox, IE, Edge Chromium (Selenium 4), Safari, Opera.
- Installation: Java, Selenium-Standalone Server, Client Language Bindings, and Drivers
- Architecture: Layered Architecture based on JSON Wire Protocol
- Wait: Implicit, Explicit, and Fluent waits
- Page Object Model can be implemented
- Assertions are brought into play using Assert class
- Screenshots: We have to make use of TakesScreenshot interface and use the method called getScreenshotAs.
- Video Recording: No direct video recording facility available (Needs Browserstack support (Paid service))
- Multiple Pages and Tabs: Need to switch between tabs, frames, etc. before every interaction
- Handling popups is done using Window Handles or in some cases using Robots class
- API Automation: Need to use libraries and respective classes for REST etc.
- Reporting: Need external reporting services like Allure, Extent Reports, etc.
- More support is available since it has been around for a decade
- Supports real device clouds Mobile Testing is available using Appium
Now that you know the difference between the two it is time you zero in on the one that you think is an apt contender.
I personally feel Playwright walks in with a learning curve apart from the above-mentioned benefits. It is new and happening now and supports both API and UI without the need to switch to a different framework.
Almost everyone sitting in an interview knows Selenium but it would be a turnaround if you learn a newer technology like Playwright. Many companies who wish to stay ahead of the curve are already choosing Playwright over Selenium.
So why not learn more?
2 Responses
[…] If you liked the above tutorial on Getting Started with Playwright, recommend you to check this other comparison article of Playwright against Selenium. […]
[…] If you liked this tutorial on how to pause in playwright, you can see why I have been pushing on wanting everyone to learn playwright. […]