Introduction
Tests that click through a browser used to be flaky: the test clicked before the page was ready, or grabbed the wrong element after a redesign. Playwright, released by Microsoft in 2020, fixes most of that by driving real Chromium, Firefox, and WebKit browsers and waiting for elements to be ready before it acts. It is now a standard choice for end-to-end tests, from a marketing page to a full checkout flow.
Real browsers, auto-waiting, and locators
Playwright rests on a few distinctive ideas:
- Real browsers, three engines: one API drives Chromium, Firefox, and WebKit, so a test can prove a page works in every engine, not just one.
- Auto-waiting: clicks, fills, and assertions wait for the element to be actionable, which removes most of the sleeps and retries that made older browser tests flaky.
- Locators that read like intent: find elements by role, label, or text, so tests describe what the user sees instead of fragile CSS paths.
- Tooling that helps debugging: code generation records your clicks into a test, traces replay failures step by step, and screenshots show exactly what the browser saw.
A tiny example shows the shape, a test that loads a page and checks its heading:
const { test, expect } = require('@playwright/test');
test('example page has a heading', async ({ page }) => {
await page.goto('https://example.com/');
await expect(page.getByRole('heading', { name: 'Example Domain' })).toBeVisible();
});
page.goto loads the page, getByRole('heading', ...) finds the heading the way assistive technology would, and toBeVisible waits for it automatically instead of checking instantly. If the heading appears a moment later, the test still passes.
The honest trade
Playwright trades speed and simplicity for realism: browser tests are slower than unit tests, they need browsers installed, and they can still be flaky around third-party widgets and animations. When to reach for it: for flows that must work in a real browser, like sign-up or checkout; unit tests for logic, and API tests for backends, where a browser adds nothing.
Test what the user sees
Playwright is browser tests that act like a real user: real engines, auto-waiting, and locators that describe intent, in tests that read like a visitor's journey. It trades test speed for confidence in the real thing, and for the flows that must not break, that confidence is worth the wait.
Top comments (0)