What Playwright is and how it works
Playwright is a framework for end-to-end (e2e) tests of web applications, with its own runner and assertions. It opens your site in a real browser and checks what a user would see. Tests run in Chromium, Firefox and WebKit on Windows, Linux and macOS, headless and in parallel, on a laptop or in CI.
It suits checks of user scenarios such as sign-up, forms, a shopping basket and signing out, as well as mobile device emulation and mixed runs where UI steps alternate with API requests. For logic that needs no browser (functions, calculations, file handling) an end-to-end test is overkill: use unit tests instead, see the pytest reference. Browser-based load testing is a separate topic, covered in the “Load testing” reference.
The Playwright Test runner reads the playwright.config.ts configuration, finds the tests and hands them out to workers: separate processes that run at the same time. Each worker has a browser open, and for every test it creates a new browser context with its own cookies and storage; the context holds a page. As a result, state does not leak from one test to the next: a failed test does not break its neighbours, and the order of execution does not matter.
A test is a function that the runner calls. It receives fixtures: ready-made objects that the runner creates before the test starts and cleans up afterwards. The main built-in fixtures are page, an open page, and context, its context. An assertion such as expect(page).toHaveTitle(...) waits for the condition to hold by itself; this is a web-first assertion. Actions also wait until the element is ready, which is called auto-waiting. For details, see the sections “Actions and auto-waiting” and “Assertions (expect)”.
import { test, expect } from '@playwright/test'; test('home page opens', async ({ page }) => { await page.goto('https://example.com/'); await expect(page).toHaveTitle(/Example/);});How it differs from Playwright Library
Playwright has two parts: @playwright/test, the runner with fixtures and assertions described above, and playwright, Playwright Library, an API for launching and controlling a browser from any script. The table shows the difference.
| Aspect | Playwright Test | Playwright Library |
|---|---|---|
| Launch | the npx playwright test command | your own Node.js script |
| Fixtures | built in: page and context are created for you | you create the browser and context yourself |
| Isolation | a new context for every test, no setup | you create and close contexts yourself |
| Parallelism | workers, retries and sharding are built in | you organise it yourself |
| Reports | HTML report, trace, UI Mode | console output; the rest is up to you |
| When to use | end-to-end tests of an application | browser automation in a script, without tests |
Choose Playwright Test for end-to-end tests: isolation, parallelism, assertions and reports are already built in. The playwright library is for driving a browser from an ordinary script without a runner: routine automation, demos and scraping data from pages.
This reference is written for Node.js and TypeScript. Official versions of Playwright also exist for Python, Java and .NET; in the Python world, end-to-end tests are written with a pytest plugin that provides the same fixtures and context isolation. Each language has its own documentation on playwright.dev.
What you need to know first
- JavaScript and TypeScript are the language of the tests: functions,
async/await, modules, types. See the JavaScript and TypeScript references. - HTML and CSS show what a page is made of: locators find elements by structure, role and text. See the HTML and CSS reference.
- Node.js and npm are the environment the runner lives in: installing packages, running via
npx. See the Node.js reference.
Section sources
the section is written from these pages- Installationplaywright.dev/docs/intro(opens in a new tab)
- Libraryplaywright.dev/docs/library(opens in a new tab)
- Browsersplaywright.dev/docs/browsers(opens in a new tab)
- Isolationplaywright.dev/docs/browser-contexts(opens in a new tab)
- TestConfigplaywright.dev/docs/api/class-testconfig(opens in a new tab)
- Installation — Playwright for Pythonplaywright.dev/python/docs/intro(opens in a new tab)