What is Playwright?
Built by Microsoft, Playwright is a Node.js library that, with a single API, automates Chromium, Firefox, and WebKit. These APIs can be used by developers writing JavaScript code to create new browser pages, navigate to URLs and then interact with elements on a page. In addition, since Microsoft Edge is built on the open-source Chromium web platform, Playwright can also automate Microsoft Edge.
Interest:
The interest in using the Playwright testing tool by developers and QA testers has also shown consistency i.e., 70% as per both 2020 and 2021 survey.
Usage:
As Playwright is comparatively new testing framework, it has shown a significant increase in its usage by developers and testers from 3% in 2020 to 10% in 2021 indicating positive growth in the coming years.
Why use Playwright for Web Automation?
Playwright is an open-source framework developed by Microsoft and released in 2020. It is relatively new to the market but has gained popularity quickly. Microsoft continues to update and improve it based on user feedback, so if we look at the number of downloads for similar frameworks that have been on the market longer than Playwright, you can see how popular it has become.
Integrations:
Playwright comes with native integration. For example, the Playwright has Docker images, allowing you to run tests quickly in an isolated and controlled environment. Native integrations are available for the best CI/CD tools, including GitHub Actions, Azure Pipelines, CircleCI, Jenkins, and GitLab. They also support your existing JavaScript test runners, like Jest/Jasmine, AVA, and Mocha, which is helpful if you are porting from an existing code base.
Lastly, Playwright has direct integration with Selenium grid online. This is essential for running larger suites of tests at scale and managing parallel execution through Selenium Grid.
Features of Playwright testing framework:
features of the Playwright testing framework
The framework supports cross-browser development on Chromium, WebKit, and Firefox – including Chrome, Edge, Firefox, Opera, and Safari.
Cross-platform execution is supported on Windows, Linux, and macOS.
Testing cross-language, including JavaScript, TypeScript, Python, Java, and .NET – choose the environment that suits you while still covering all areas and formats.
Auto-wait, smart assertions that retry until an element is found, and test data tracing – keep track of logs and videos easily.
Built with modern architecture and no restrictions, the application allows you to interact with multi-page, multi-tab websites like a real user and easily handles frames and browser events.
As the Playwright framework is aligned with the modern browser’s architecture, it doesn’t have the in-process test runner limitations.
Playwright delivers full test isolation with no overhead. It creates a browser context for each test which only takes a handful of milliseconds.
Advantages of Playwright:
The Playwright framework helps you perform cross browser testing on sophisticated web applications. It provides accurate results and offers excellent test coverage. In addition, it has multiple advantages to automate your web testing. Some of them are as follows.
Supports testing scenarios for multi-tab, multi-user, and iframes.
It’s available as a VS Code extension to run tests in a single click and comes with features for step-by-step debugging, exploring selectors, and recording new tests.
Generate an HTML report to view test execution results in the browser. It contains visual mismatches and test artifacts like screenshots, traces, error logs, and video recordings.
Installing Playwright doesn’t take long, as it requires a configuration. However, the installation process can differ based on your programming language with Playwright to run the tests.
It supports different types of testing like end-to-end, functional, and API testing.
Offers support for automated accessibility testing using a third-party plugin.
It provides different debugging options like Playwright Inspector, Browser Developer Tools, VSCode Debugger, and Trace Viewers Console Logs.
It has in-built reporters like JSON, JUnit, and HTML Reporters. With Playwright, you can also create custom reporters.
Run parallel test execution locally or on an online Selenium grid. You can also share tests between systems to run multiple tests in parallel
Playwright testing Drawbacks:
Here are some Playwright testing drawbacks
Playwright does not support legacy Microsoft Edge or IE11.
A single test() function captures screenshots, videos, and failure traces. In other words, if you have a few tests inside a test.describe() function, you will get videos and traces for each one but not for the entire root test function.
Playwright uses desktop browsers instead of real devices to emulate mobile devices.
Even though Playwright supports API testing, its APIRequest method doesn’t support disabling follow redirects.
It doesn’t support TeamCity reporter. You need to write your reporter for CI/CD builds.
Playwright Architecture:
To understand how Playwright’s architecture works, we will compare its work with that of Selenium. Selenium sends each command as an independent HTTP request and receives JSON responses. Each interaction, such as opening a browser window, clicking an element, or entering text into an input box, then is sent as a separate HTTP request.
This means we have to wait longer for responses and increases the chances of errors
Instead of communicating with each driver through a separate WebSocket connection, Playwright relies on a single WebSocket connection to communicate with all drivers, which remains in place until testing is finished. This allows commands to be sent quickly on a single connection, thus reducing the points of failure.
Browsers Supported by Playwright:
Playwright is available in a variety of languages, and each version has different dependencies. At package install time, Playwright will either download these dependencies for you or you can use Playwright CLI to install them.
Playwright constantly updates its support of browsers, so that the latest Playwright would support the latest browsers at any time. As a result, you need to run the install command each time you update Playwright.
Chromium (84 & above)
Firefox (76 & above)
WebKit (13 & above)
Google Chrome (Chrome 66 & above)
Microsoft Edge (Edge 80 & above)