Playwright - a new player in the web automation arena | DeviQA
DeviQA Logo
  1. Home
  2. /
  3. Blog /

16 minutes to read

Playwright - a new player in the web automation arena

Playwright - a new player in the web automation arena

Share

There are varied test automation tools on the market. Puppeteer, Selenium, Cypress, and Protractor, are traditionally considered to be the market leaders when it comes to web app testing. Still, now they have a new tough competitor represented by Playwright. Let’s try to shed light on this tool!

What is Playwright?

Playwright is a relatively new framework for accurate end-to-end testing of modern sophisticated web applications. What is important is that the framework is open-source.

The first version of Playwright appeared in January 2020. Since that time it has managed to grow in popularity.

In essence, in many ways, Playwright resembles Puppeteer. No wonder, while being owned by Microsoft, it has been created by the same team that worked on Puppeteer at Google. However, this time, developers had an aim to make a step further and develop a framework that would provide even more opportunities. The main among these opportunities is the ability of cross-browser testing. These days Playwright is the only of its kind framework supporting all modern browser engines.

Playwright can be effortlessly integrated with test runners based on JS like Jest, Mocha, and Ava. However, its own Folio-based test runner, Playwright Test, is also available.

At the core of Playwright lies the Browser-Context-Page concept. Let’s consider it step by step.

Browser: a browser is launched by means of an object of the browser class that, in fact, is a browser instance.

Context: A browser context can be defined as an isolated, independent environment within a browser instance. This approach enables parallelization. If Playwright Test is leveraged, each test scenario is run in its own context by default. Otherwise, it is possible to create a browser context manually. Additionally, several browser contexts can be created within a single scenario, which is helpful when it comes to testing multi-user functionality.

Page: This is a tab or a popup within a browser context. Each action executed by a test is on this object.

What is Playwright Automation

Playwright automation is the process of using the Playwright open-source tool to automate the testing of web applications. Playwright allows developers to write automated tests in JavaScript or TypeScript that simulate user interactions with web applications, such as clicking buttons, entering text, and navigating pages.

Playwright provides a range of features to support automation, including the ability to test web applications across multiple browsers, including Chromium, Firefox, and WebKit. It also supports headless testing, which allows tests to be executed without opening a visible browser window, improving the speed and efficiency of the testing process.

Playwright automation can help to ensure the functionality and performance of web applications, detecting issues early in the development process and allowing developers to make necessary changes before releasing the application to production. By automating the testing process, Playwright can also save time and resources compared to manual testing, while providing more reliable and consistent results.

Overall, Playwright automation is a powerful and flexible way to test web applications, designed to make the testing process faster, more reliable, and more efficient.

Benefits of Playwright

Playwright has numerous advantages due to which even hardcore fans of Selenium or Puppeteer can be tempted to give it a try. So, let’s dive deeper and consider the numerous capabilities of this framework.

Playwright can be quickly and easily installed and configured.
Safari, Firefox, and Chromium family browsers are supported.
As a cross-platform framework, it supports all common operating systems - Windows, macOS, and Linux.
Either headed or headless modes are provided.
The most generally used programming languages like JavaScript, TypeScript, Python, and .NET are supported.
The concurrent test execution is enabled by Browser Context. Tests can be run simultaneously within several browsers.
Repetitive log-ins can be avoided while keeping tests isolated and independent. For this purpose, an authentication state of a browser context should be saved and then reused in the rest of the tests.
Playwright gives an opportunity to test throughout a number of tabs or browser windows, which is helpful when test cases cover a scenario that entails launching a new window with further returning to an original window.
Tests can be run on CI and other environments that support Docker.
Playwright is smoothly integrated with common continuous integration and continuous delivery solutions such as Jenkins, Azure Pipeline, CircleCI, TravisCI, etc.
HTTP and HTTPS network traffic can be controlled and modified.
All pages of a browser context can be video recorded. Moreover, there is an opportunity to take full-page screenshots or screenshots of a certain page element.
Devices, geolocation, language, timezone, as well as different browser properties like a color scheme and viewport size, can be effortlessly emulated.
Auto-wait and web-first assertions significantly simplify the life of automated QA engineers by helping to avoid flaky tests. The auto-wait feature suggests that Playwright cannot perform any action until all the required checks of elements are passed. Assertions are created particularly for the dynamic web, and checks are auto-repeated until the required conditions are met.
Playwright gives opportunities to cover all possible scenarios.
There is an opportunity to generate tests by recording user actions. Just run Codegen and perform the needed actions. Code can be generated in any of the supported programming languages with the use of resilient selectors.
Playwright can work with browser developer tools and Node.js debuggers. Additionally, it offers its own debugging features. For example, Playwright Inspector is a default recommended GUI tool to troubleshoot scripts. Playwright Trace Viewer is one more GUI tool enabling users to explore recorded traces as soon as a test run is completed.
Playwright Test offers several built-in test reporters for diverse needs. A few reporters can be leveraged at the same time. Besides, a custom reporter can be also created. Additionally, such test report tools as Allure and Tesults can be integrated as well.

As you see, Playwright is a technology that indeed deserves attention. If you would like to go into the nitty-gritty, please have a look at the documentation on the official website.

Playwright Supported Browsers

One of the key features of Playwright is its ability to support multiple browsers, including Chromium, Firefox, and WebKit. This means that developers can use Playwright to test their web applications across a variety of platforms, ensuring that they are functional and performant for users regardless of the browser they use.

Drawbacks of Playwright

No garden without its weeds. Thus, in spite of having a wide scope of merits, Playwright also has certain limitations. The main among them are:

It does not support Internet Explorer 11, as well as legacy Microsoft Edge.
While Playwright has been created with the aim to support numerous programming languages, temporarily it is impossible to use its API in Java or Ruby.
There is no opportunity to run scripts on real mobile devices.
Since Playwright is a new market player, currently it cannot boast of solid community support.

Puppeteer vs Playwright

PlaywrightPuppeteer
Browser supportChromium, Firefox, WebKit (experimental)Chromium
APIsHigher-level APIs with more built-in featuresLower-level APIs with more control over individual actions
PerformanceFaster and more reliable due to improved event handlingSlightly slower due to less efficient event handling
DebuggingEasier to debug with more detailed error messagesLess detailed error messages
Multi-page appsBetter support for multi-page apps with automatic context switchingContext switching needs to be done manually
CommunityGrowing community with active development and supportMature community with extensive documentation and resources
LicensingApache 2.0 licenseMIT license
UsageSuitable for testing, scraping, and automation of web applicationsSuitable for automation of web applications and scraping tasks

In summary, both Playwright and Puppeteer are great tools for automating web applications and scraping tasks, but they have some differences in their APIs, browser support, performance, debugging, and community support. Playwright is a newer tool with higher-level APIs, better multi-page app support, and faster event handling, while Puppeteer is a more mature tool with a larger community, extensive documentation, and more control over individual actions. Ultimately, the choice between the two will depend on your specific use case and preferences.

Playwright vs Cypress

PlaywrightCypress
Browser supportChromium, Firefox, WebKit (experimental)Chromium-based (Chrome, Edge, Firefox)
APIsHigher-level APIs with more built-in featuresHigher-level APIs with less built-in features
PerformanceFaster and more reliable due to improved event handlingSlightly slower due to overhead of running in-browser
DebuggingEasier to debug with more detailed error messagesEasier to debug with built-in dashboard and time-travel features
Multi-page appsBetter support for multi-page apps with automatic context switchingMulti-page apps require manual setup with cy.visit()
CommunityGrowing community with active development and supportMature community with extensive documentation and resources
LicensingApache 2.0 licenseMIT license
UsageSuitable for testing, scraping, and automation of web applicationsSuitable for testing and debugging web applications

In summary, both Playwright and Cypress are popular tools for testing web applications, but they have some differences in their APIs, browser support, performance, debugging, and community support. Playwright has higher-level APIs, better multi-page app support, and faster event handling, while Cypress has a built-in dashboard with time-travel features and supports a wider range of browsers. Ultimately, the choice between the two will depend on your specific use case and preferences.

Playwright vs Selenium

PlaywrightSelenium
Browser supportChromium, Firefox, WebKit (experimental)All major browsers (Chrome, Firefox, Safari, Edge, Internet Explorer)
APIsHigher-level APIs with more built-in featuresLower-level APIs with more control over individual actions
PerformanceFaster and more reliable due to improved event handlingSlower due to legacy architecture and less efficient event handling
DebuggingEasier to debug with more detailed error messagesMore difficult to debug with less detailed error messages
Multi-languageSupports multiple programming languages (JavaScript, Python, Java, .NET)Supports multiple programming languages (Java, C#, Python, Ruby, JavaScript)
CommunityGrowing community with active development and supportMature community with extensive documentation and resources
LicensingApache 2.0 licenseApache 2.0 license
UsageSuitable for testing, scraping, and automation of web applicationsSuitable for testing and automation of web applications

Conclusion

Playwright is a brand new solution for web testing offering awesome automation capabilities. With its help, it is possible to write fast, accurate, and reliable tests covering the most diverse scenarios. Since its recent inception, it has immensely evolved. Currently, the 71st release is available, and the development team is not going to stop. It may safely be said that Playwright will have a bright future. Our QA engineers provide automated testing with playwright

Share