Fast and reliable cross-browser testing with Playwright 🎭
Tags: testing, webdev, javascript
Published: 2020-05-06 20:35:22

Web developers today are shipping faster. Web apps are becoming increasingly sophisticated and run across all devices—our phones, tablets and desktops—each running a different browser engine. This increase in velocity and targets puts immense pressure on the testing process: automated cross-browser testing has become more important than ever.

Automated end-to-end tests can be incredibly powerful: by replicating user interactions, they can verify functionality, usability and performance—at least in theory. In practice, end-to-end tests can be slow, flaky and hard to maintain.

Today we are announcing [Playwright](https://github.com/microsoft/playwright) – our take on fixing end-to-end testing. Playwright is a **cross-browser automation library** to write tests that are **fast, reliable and capable**.

![Playwright capabilities across Chromium, Firefox and WebKit](https://user-images.githubusercontent.com/284612/81224868-37fa2800-8f9d-11ea-8332-604a68737b0d.png)

Playwright can test web apps across multiple browsers: Chromium-based browsers like **Google Chrome** and the **new Microsoft Edge**, WebKit-based **Apple Safari** and the Gecko-based **Mozilla Firefox**. Playwright 1.0 is [available today on NPM](https://www.npmjs.com/package/playwright).

With a single API, Playwright can automate a wide-range of scenarios across different browsers, with a foundation that emphasizes reliable and fast execution.

![Getting started with Playwright](https://user-images.githubusercontent.com/284612/81224828-2add3900-8f9d-11ea-86b6-a272d56879b1.gif)

## Increased reliability with timeout-free automation

Modern web apps need to be rich and interactive, and dynamically respond to user actions. This asynchronous behavior makes modern apps harder to predictably automate. A network request can take slightly longer than usual and keep the loader spinning.

Playwright automatically waits for the UI to be ready, which helps create tests that are **reliable to execute** and **simpler to author**. For example, a page click will auto-wait for the target element to be visible and ready. Developers and testers can write tests that focus on the scenario, and not on timing or UI state. This significantly improves the maintainability of test code over time.

Under the hood, Playwright uses an **event-driven architecture** that can listen to browser events. Playwright tests can accurately wait for DOM changes, network requests or even new console logs. Playwright uses the same protocols that power browser developer tools — tools that developers have grown to love.

With precise browser events, automation scripts can avoid timeouts. In traditional end-to-end testing, waiting for the app to be ready was often the only way to manage asynchronous behavior. However, timeouts are a slippery slope: they always lead to inconsistent failures or "flaky tests".

![Auto-waits on page actions and APIs for more granular control](https://user-images.githubusercontent.com/284612/81224841-2dd82980-8f9d-11ea-9aef-86a5215a8efe.gif)

## Automation that scales: fast, parallelized execution

Playwright is built to deliver **fast, parallelized automation** in local and cloud environments. A single instance of Chromium, Firefox or WebKit can create multiple isolated and concurrent browser contexts. This significantly improves performance and enables independent **multi-page emulation scenarios**.

A single browser context can host multiple web pages and define context-level behavior, such as network interception or authentication credentials. Browser contexts can also emulate mobile viewports, mock geolocation and locale. This enables a single WebKit instance to run multi-page scenarios across multiple device configurations in parallel: desktop, iPhone and iPad.

![Browser contexts are isolated environments and can emulate various scenarios](https://user-images.githubusercontent.com/284612/81224855-32044700-8f9d-11ea-819f-709a0bde4d6b.gif)

## Automating the web of today and tomorrow

The web platform is more capable than ever before and is [continuously evolving](https://whatwebcando.today/). Playwright is built to keep up with growing capabilities of web browsers and web apps. This also includes newer browser features that are used by Progressive Web Apps (PWAs). Playwright can automate a wide-range of capabilities across Chromium, Firefox and WebKit, with a single API.

* Emulation of mobile viewports, permissions, geolocation and locale
* Support for web components via shadow-piercing selectors
* Network interception for modifying and mocking network activity
* File uploads and downloads
* Scenarios that span multiple frames, tabs and pop-ups
* Trusted native input events from mice and keyboards
* Web workers and out-of-process iframes

![Playwright can intercept network requests-to abort, modify or mock them](https://user-images.githubusercontent.com/284612/81224848-2fa1ed00-8f9d-11ea-8f03-62a9117222ae.gif)

## Get started with Playwright: on local and CI
Playwright 1.0 is [available on NPM](https://www.npmjs.com/package/playwright) and is ready to use today. The [getting started guide](https://playwright.dev/#path=docs%2Fintro.md) is a good place to start. Playwright is built to be modular, and can be [used with all popular test runners](https://playwright.dev/#path=docs%2Ftest-runners.md).

To complement the Playwright NPM package, we are also releasing a [GitHub Action to run Playwright tests](https://github.com/marketplace/actions/run-playwright-tests) in your CI/CD pipelines with GitHub Actions.

## Thank you!

Playwright is [developed in the open on GitHub](https://github.com/microsoft/playwright). We are grateful to our [early adopters](https://github.com/microsoft/playwright/blob/master/docs/showcase.md), who have shared painstaking details into their use-cases and have helped shape the Playwright API.

Playwright is also standing on the shoulders of giants. It would not have happened if not for the efforts of these exceptional teams working on browser engines and automation solutions. We are grateful to:

* The Chromium, Chrome DevTools and Puppeteer teams for working with us upstream
* The WebKit and Web Inspector teams at Apple, Sony, Igalia and elsewhere for accepting our WebKit patches and making WebKit run on Windows and as headless on Linux
* The Firefox team for their efforts in supporting newer automation drivers
* The WebDriver team for pioneering automated end-to-end testing and bringing it to scale

—on behalf of the Playwright team