Setup
npm init playwright@latest
Scaffold config, example tests and CI file
npx playwright install
Install the default browsers
npx playwright install --with-deps
Install browsers and system libraries
Needs sudo on Linux; the usual step in CI images.
npx playwright install <browser>
Install one browser (chromium, firefox, webkit)
npx playwright clear-cache
Clear build and test caches
npm install -D @playwright/test@latest
Update Playwright
Running tests
npx playwright test
Run every test headless
npx playwright test <file>
Run files matching a path regex
npx playwright test <file>:<line>
Run the test at a line
npx playwright test -g "<title>"
Run tests whose title matches
npx playwright test -G "<title>"
Skip tests whose title matches
npx playwright test --project=<name>
Run one project (browser)
npx playwright test --headed
Show the browser window
npx playwright test --last-failed
Re-run only the failures
npx playwright test --only-changed
Run files changed since HEAD
npx playwright test --list
List tests without running
npx playwright test -x
Stop after the first failure
npx playwright test -c <file>
Use another config file
Debugging
npx playwright test --ui
Interactive UI mode with time travel
npx playwright test --debug
Run with the Inspector, headed, 1 worker
npx playwright test --trace on
Record a trace for every test
npx playwright test --trace retain-on-failure
Keep traces only for failures
npx playwright show-trace <trace.zip>
Open a trace in the viewer
npx playwright test --timeout <ms>
Per-test timeout (default 30000)
npx playwright test --repeat-each <N>
Run each test N times (find flakes)
Parallelism and CI
npx playwright test --workers <N>
Number of workers or a percent of cores
npx playwright test --workers=1
Run serially in one worker
npx playwright test --fully-parallel
Run tests of one file in parallel too
npx playwright test --retries <N>
Retry failed tests N times
npx playwright test --shard <n>/<total>
Run one slice, e.g. 2/4
npx playwright test --forbid-only
Fail if test.only is left in
npx playwright test --fail-on-flaky-tests
Fail when a test only passed on retry
npx playwright merge-reports <dir>
Merge sharded blob reports
Reports and output
npx playwright show-report
Open the last HTML report
npx playwright show-report <dir>
Open a report folder or zip
npx playwright test --reporter <name>
Choose reporters: list, line, dot, html, json, junit
npx playwright test --reporter=html,list
Combine reporters, comma separated
npx playwright test --output <dir>
Folder for artifacts (test-results)
Codegen
npx playwright codegen <url>
Record actions into test code
npx playwright codegen -o <file>
Save the generated script
npx playwright codegen --target <lang>
Pick the language, e.g. python
npx playwright codegen -b <browser>
Record in firefox or webkit
npx playwright codegen --device
"<name>"
Emulate a device
npx playwright codegen --save-storage <file>
Save logged-in state
The file holds cookies and tokens; keep it out of git.
npx playwright codegen --load-storage <file>
Start from saved state