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.
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.
fulfill, continue, or abort. To
observe a real response instead, wait for it:
Handle a dialog
An unhandledalert, confirm, or prompt fails the next step. Register a
handler first:
accept(text?) or
dismiss().
Download a file
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.
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
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.
