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.
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 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.
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.
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