Playwright
- Pronunciation
- PLAY-rite
In short
Playwright is Microsoft's open-source framework for end-to-end testing and browser automation, driving Chromium, Firefox and WebKit through one API.
What is Playwright?
Playwright was released by Microsoft in 2020, built by engineers who had earlier created Puppeteer at Google. It controls real browsers, Chromium for Chrome and Edge, Firefox, and WebKit, the engine behind Safari, so a single test can check that a sign-up or checkout flow works the same everywhere. Tests can be written in JavaScript or TypeScript, Python, Java or .NET.
A test opens a page, finds elements and acts on them as a user would: clicking, typing, choosing from menus and uploading files. Locators such as getByRole("button", { name: "Sign in" }) find elements the way people and screen readers see them, which keeps tests stable when the markup changes. Before every action, Playwright waits automatically until the element is visible and enabled, which removes most of the timing problems that make browser tests flaky.
Playwright Test, its built-in test runner, runs tests in parallel, emulates phones and screen sizes, can intercept network requests and compares screenshots. When a test fails on CI, the trace viewer replays every step with screenshots, DOM snapshots and network calls. A code generator can record clicks in a browser and turn them into a test.
A common misconception is that Playwright replaces unit tests. End-to-end tests are slower and check whole user journeys, so they sit at the top of the test pyramid; fast unit and integration tests should still cover most of the logic. Compared with Selenium and Cypress, Playwright is newer and supports multiple browsers, tabs and origins in one test out of the box.
Key takeaways
- Playwright automates Chromium, Firefox and WebKit through one API.
- Role-based locators find elements the way users see them.
- Auto-waiting before every action reduces flaky tests.
- Its test runner adds parallel runs, device emulation, screenshots and traces.
- End-to-end tests complement, not replace, unit and integration tests.
Example
import { test, expect } from "@playwright/test";
test("a user can sign in", async ({ page }) => {
await page.goto("https://example.com/login");
await page.getByLabel("Email").fill("ada@example.com");
await page.getByLabel("Password").fill("correct horse battery");
await page.getByRole("button", { name: "Sign in" }).click();
// Waits automatically until the heading appears
await expect(page.getByRole("heading", { name: "Welcome, Ada" })).toBeVisible();
});Readers ask
What is the difference between Playwright and Selenium?
Both automate real browsers. Selenium is older, uses the WebDriver standard and supports many languages and browsers. Playwright talks to browsers more directly, waits automatically and includes a modern test runner, tracing and network control.
What is the difference between Playwright and Cypress?
Cypress runs tests inside the browser and is known for its interactive runner. Playwright controls browsers from outside, which makes multiple tabs, origins and browsers, including WebKit, straightforward.
Can Playwright be used for things other than testing?
Yes. It is also used for browser automation in general, such as taking screenshots, generating PDFs and scraping pages, and by AI agents that operate websites.
Often compared
See also
- End-to-End TestTesting & Quality, p. 8An end-to-end test is an automated test that runs a complete user journey through the whole application, from the user interface to the database and back.
- Test RunnerTesting & Quality, p. 33A test runner is a tool that finds a project's automated tests, executes them, and reports which ones passed or failed, usually from a single command.
- Flaky TestTesting & Quality, p. 10A flaky test is an automated test that sometimes passes and sometimes fails without any change to the code, which makes its results hard to trust.
- Test PyramidTesting & Quality, p. 32The test pyramid is a model for balancing automated tests: many fast unit tests, fewer integration tests, and only a few slow end-to-end tests at the top.
- Regression TestingTesting & Quality, p. 22Regression testing is the practice of re-running existing tests after a code change to make sure that features which used to work have not broken.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
- CypressTesting & Quality, p. 7Cypress is a JavaScript framework that runs end-to-end and component tests for web apps inside the browser, with automatic waiting and an interactive runner.
- SeleniumTesting & Quality, p. 23Selenium is an open-source suite of tools for automating web browsers, used mainly for end-to-end testing, with its WebDriver API available in many languages.
Spotted a mistake or something missing on this page?Suggest an edit