App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide Playwright vs Selenium: Which to choose?

Playwright vs Selenium: Which to choose?

By Garima Tiwari, Community Contributor -

What is Playwright?

Playwright by Microsoft is the newest addition to the Headless Browser Testing frameworks in popular use. Built by the same team that created Puppeteer (Headless Browser Testing Framework for Google Chrome), Playwright is an open-source NodeJS-based framework. 

Playwright Logo

  • However, it provides wider coverage for cross-browser testing by supporting Chrome, Firefox, and WebKit, while Puppeteer only supports Chrome and Chromium browsers.
  • Playwright is compatible with Windows, Linux, and macOS, and can be integrated with major CI/CD servers such as Jenkins, CircleCI, Azure Pipeline, TravisCI, etc. in addition to the testing frameworks like Jest, Jasmine, Mocha.
  • Besides JavaScript, Playwright also supports multiple programming languages such as Python, Java, and .NET C#, giving more options to QAs writing test scripts.
  • It is highly useful for cross-browser testing on complex applications due to its wide coverage, accuracy, and high speed. It offers end-to-end testing through its high-level API, allowing the tester to control headless browsers.

When the tester runs a Playwright test script, the UI is readied at the backend before the test interacts with web elements. While testers have to write code for the wait explicitly for other frameworks, Playwright ensures auto wait, making it easier to write concise test scripts. It also provides flexible testing through its capabilities, which cover a wide range of complex scenarios for comprehensive testing.

  • The auto-wait feature in Playwright performs all relevant checks for an element, and the requested action is performed only when the checks are duly passed. This ensures that the parts perform as expected and the test results are more accurate.
  • Some actionability checks performed by Playwright include Attached, Visible, Stable, Receive Events, and Enabled.
  • Playwright also supports the execution of simultaneous tests (AKA parallel testing) through Browser Context. This scales up testing and comes in handy when multiple web pages must be tested simultaneously.

Here one browser instance is used to create multiple, concurrent and isolated browser contexts, which can be closed when not needed. Each of these browser contexts could host multiple web pages simultaneously. Thus, scaling up when the volume is high and reducing it when not required ensures optimal usage of resources.

How to run Playwright tests

While Playwright launches browsers in the headless mode by default, it can also run the browsers in headful mode. By passing a flag, when the browser is launched, Playwright can be used to run browsers in headful mode for tests. 

The following code can be used to launch a headful browser:

const { chromium } = require('playwright'); 

//to launch the headful browser for firefox and webkit, replace chromium by firefox and webkit

const browser = await chromium.launch({ headless: false });

For Linux systems, xvfb is essential for launching headful browsers. Since xvfb is pre-installed in Docker Image and Github Action, running xvfb before the Node.js command allows the browsers to run in the headful mode.

xvfb-run node index.js

What is Selenium?

Selenium is an open-source automation testing suite that is widely used for the automation testing of web applications. It automates browsers and interacts with UI elements to replicate user actions to test whether a web application is functioning as expected.

Selenium Logo

Through its single interface, the Selenium framework allows the tester to write test scripts in different languages such as Java, Ruby, Perl, C#, NodeJS, Python, and PHP, offering flexibility. 

  • Selenium supports a wide range of browsers and their different versions to enable cross browser testing of web applications.
  • It is the most popular framework to test websites and ensure seamless and consistent user experiences across different browser and device combinations.
  • That is why Selenium is one of the most trusted automated testing suites in the software industry.

Playwright vs Selenium: Which to choose?

Playwright vs Selenium Comparison 

CriteriaPlaywrightSelenium
LanguageSupports multiple languages such as JavaScript, Java, Python, and .NET C#Supports multiple languages such as Java, Python, C#, Ruby, Perl, PHP, and JavaScript
Ease of InstallationEasy to InstallEasy to Install
Test Runner Frameworks SupportedMocha, Jest, JasmineMocha, Jest, Jasmine, Protractor, and WebDriverIO
PrerequisitesNodeJS should be installedJava, Eclipse IDE, SeleniumStandalone Server, Client Language Bindings, and Browser Drivers should be installed
Operating Systems SupportedWindows, Linux, and Mac OSWindows, Linux, Solaris, and Mac OS
Open SourceOpen Source and FreeOpen Source and Free
ArchitectureHeadless Browser with event-driven architectureLayered Architecture based on JSON Wire Protocol
Browsers SupportedChromium, Firefox, and WebKitChrome, Firefox, IE, Edge, Opera, Safari, and more
SupportSince Playwright is fairly new, the support from the community is limited as compared to SeleniumProvides commercial support for its users via its sponsors in Selenium Ecosystem and self-support documents. Strong community support from professionals across the world 
Real Devices SupportIt does not support real devices but supports emulatorsSupports real device clouds and remote servers

Playwright vs Selenium: Which to choose?

Both Playwright and Selenium have advantages and limitations, which means choosing between them is subjective to the scenario they will be used for.

Although Playwright offers fast testing in complex web applications with headless architecture and requires NodeJS as a prerequisite, it is relatively new. It lacks support on various levels, such as community, browsers, real devices, language options, and integrations. Selenium has all of this to offer.

However, each supports CI/CD for a software project with due accuracy. Playwright has the upper hand in complex web applications, but has limited coverage. On the contrary, Selenium offers comprehensive coverage, scalability, flexibility, and strong community support.

Thus, it depends on the project requirements and the priorities to choose one among these two testing frameworks. When the architecture is very complex with limited coverage, then Playwright is the option to select for testing. In a scenario that requires wider coverage, Selenium is the best bet.

Closing Notes

No matter which test automation framework is chosen, cross browser testing is mandatory. It is the only way to guarantee that the website delivers seamless and consistent UX, irrespective of the device and browser used to access them.

  • However, Emulators and simulators simply do not offer the real user conditions for testing software.
  • Consider testing websites and apps on a real device cloud, preferably one that offers the latest devices, browsers, and OS versions.
  • This applies to both manual testing and automation testing.

BrowserStack’s real device cloud provides 3000+ real browsers and devices for an instant, on-demand testing.

  • It also provides a cloud Selenium grid for automated testing, which can be accelerated by 10X with parallel testing.
  • The cloud also provides integrations with popular CI/CD tools such as Jira, Jenkins, TeamCity, Travis CI, and more.
  • Additionally, in-built debugging tools let testers identify and resolve bugs immediately.

Try Automation Testing on Cloud

Tags
Playwright Selenium

Featured Articles

Puppeteer vs Selenium: Core Differences

Choosing the Right Automation Tool: Appium vs Selenium

Curated for all your Testing Needs

Actionable Insights, Tips, & Tutorials delivered in your Inbox
By subscribing , you agree to our Privacy Policy.
thank you illustration

Thank you for Subscribing!

Expect a curated list of guides shortly.