DEV Community

Arjun Attam
Arjun Attam

Posted on

Fast and reliable cross-browser testing with Playwright 🎭

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

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.

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

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

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

Automating the web of today and tomorrow

The web platform is more capable than ever before and is continuously evolving. 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

Get started with Playwright: on local and CI

Playwright 1.0 is available on NPM and is ready to use today. The getting started guide is a good place to start. Playwright is built to be modular, and can be used with all popular test runners.

To complement the Playwright NPM package, we are also releasing a GitHub Action to run Playwright tests in your CI/CD pipelines with GitHub Actions.

Thank you!

Playwright is developed in the open on GitHub. We are grateful to our early adopters, 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

Top comments (0)