Playwright benefits for modern web applications testing
Tags: testautomation, e2e, playwright
Published: 2022-12-10 15:30:20

>According to its headline Playwright enables reliable end-to-end testing for modern web apps. The Playwright library provides cross-browser automation through a single API.

[Playwright](https://playwright.dev/docs/intro) is a Node.js based library to automate Chromium, Firefox, and WebKit based browsers with a single API. Playwright is built to enable cross-browser web automation that is reliable, and fast. It supports programming languages such as Java, Python, C#, and NodeJS. Playwright comes with Apache 2.0 License and is most popular with NodeJS with Javascript/Typescript.

Let’s review Playwright's main features and how QA engineers benefit from them.

## Cross-browser, Cross-platform and ready for Mobile Web.
Playwright supports all modern rendering engines including Chromium, WebKit, and Firefox. So, that means QA engineers can test all major browsers using tools provided by Playwright out of the box. Also tests run on Windows, Linux, and macOS, locally or on CI, headless or headed. At the same time Playwright provides native mobile emulation of Google Chrome for Android and Mobile Safari. Using such emulation it’s possible to test mobile web both on QA engineers local machines and in the Cloud.

## Designed to run for multiple processes, work with dynamic elements and Shadow DOM.
The downside of the previous generation of test runners was that they usually run within a single process and therefore were not able to run web content belonging to different origins in different processes. Playwright is aligned with the modern browsers architecture and runs tests out-of-process. This makes Playwright free of the typical in-process test runner limitations. As a result it is possible to create test scenarios that span multiple tabs, multiple origins and multiple users. Such scenarios with different contexts for different users can run all in one test.

Playwright uses real browser input pipeline indistinguishable from the real user such as hover elements, interact with dynamic controls and produce trusted events.

Playwright comes with robust auto wait and it waits for elements to be actionable prior to performing actions. It also has a rich set of introspection events. The combination of the two eliminates the need for hardcoded timeouts which decrease flaky tests and speed up tests execution considerably. Playwright assertions are created specifically for the dynamic web. Checks are automatically retried until the necessary conditions are met. Playwright selectors pierce shadow DOM and allow entering frames seamlessly.

## Full isolation in the browser context.
Playwright creates a browser context for each test. Browser context is equivalent to a brand new browser profile. This delivers full test isolation with zero overhead cause creating a new browser context takes only a few milliseconds.

The other important benefit of the isolation is that the authentication state of the context can be saved and reused in all the tests. This allows it to bypass repetitive log-in operations in each test, yet delivering full isolation of independent tests.

## Set of powerful tools.
Playwright comes with a set of powerful tools which allow QA engineers to create, modify and debug automated tests much faster. First of all, it's Codegen which allows generating tests by recording the user's actions. With Playwright inspector it’s possible to inspect a page, generate selectors, step through the test execution, see click points, explore execution logs. Trace Viewer allows capturing all the information to investigate the test failure. Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source, and many more.

VS Code extension allows to run a test or a group of tests with a single click. While tests are running, the execution line is highlighted, once the line has completed, step time is rendered as an editor decoration.

## Conclusions
As a conclusion we can say that at [qaVisor](https://qavisor.com) Playwright is used as a powerful tool, which helped our QA engineers to solve real-life problems for our clients:

With Playwright it’s much easier to automate various user login scenarios for eg. login with Google, Facebook, Apple ID, username and password. It became possible due to browser context isolation and saving authentication state between tests.

Playwright made our automated tests much faster. It leads to the cost reduction for our clients both for testing with emulators and device farms. More tests can be executed within the same time interval compared to the previous generation tools.

Playwright is a great end-to-end automation solution for the web apps created with javascript frameworks such as React, Vue JS and Angular due to its support of dynamic elements and Shadow DOM.

Since Playwright is based on Node.js it fully integrates in the Javascript ecosystem and it does not require complex or non-trivial configuration and can be easily be used by junior QA engineers.

Playwright works well with most of the CI tools and also has great integration capabilities with 3rd party tools such as test management systems, device farms, reporting tools and a variety of test runners.

Finally Playwright is supported by Microsoft and used for testing its large projects such as Visual Studio Code and Edge browser. So it’s trusted and widely used by large companies and therefore qaVisor recommends Playwright as a tool for web application testing.