Skip to main content
screen, app, and expect cover most of a browser test and stay portable. The web fixture holds what only a browser has: routes, cookies, dialogs, frames, downloads, page evaluation. Import test from @e2edev/playwright to have it typed.
A suite that also runs on a device declares requires: ['web'] so those tests are skipped there instead of failing.

Mock an API

web.route intercepts requests for the attempt. Register it before the page opens; it stays in force across app.restart() and a session restore.
The handler decides exactly once: fulfill, continue, or abort. To observe a real response instead, wait for it:

Handle a dialog

An unhandled alert, confirm, or prompt fails the next step. Register a handler first:
A function handler gets the dialog and must call accept(text?) or dismiss().

Download a file

The file is registered as a download artifact. file.path is relative to the attempt’s artifact directory, not an absolute or project-relative file path.

Reach into an iframe

web.frameLocator scopes queries into one frame. You query inside it and act on what you find:

Read from the page

web.evaluate runs a function in the page. It is serialized, so it cannot close over test variables; pass data as the second argument.
Reach for screen and expect first. evaluate reads DOM state the accessibility tree does not expose, and a test that leans on it is tied to the page’s implementation.

Cookies and viewport

A cookie’s target origin must be one the target allows; nothing is set when any entry is rejected.

Pick a browser and viewport

The browser and the initial viewport are options of the engine. Two browsers on one app are two targets:
e2e.config.ts
npx playwright install webkit --with-deps provisions the extra browser in CI. connect attaches to a remote Chromium over CDP instead of launching one.

Raw selectors

web.locator('css or xpath') exists for the node screen cannot name. It is not portable and it ties the test to markup, so prefer a role, a label, or a test id, and use { visible: true } to drop a hidden twin before reaching for a selector.

Playwright reference

Every web method, its timeout, and what it throws.

Starting your app

Let the runner start the dev server and reach protected previews.