Debugging tools: UI mode, codegen, inspector, trace
Find out why a test fails: UI mode with a timeline of snapshots, codegen to draft locators, the inspector to step through, and the trace viewer for failures in CI.
Transcript
When a test fails, you need to see what happened. Start with U I mode. Run n p x playwright test dash dash U I. You get your tests, a list of every action, and a snapshot of the page at each step.
Not sure which locator to write? Use codegen. Run n p x playwright codegen, click through your app, and Playwright writes the code as you go. Treat it as a draft, then clean it up.
To pause and look around, run with dash dash debug. The Playwright inspector runs the test one action at a time, and can pick a locator right from the page.
When a test fails in C I, the trace viewer is your best friend. A trace is a recording of the run: every action, the page before and after, the network calls, and the console.
Remember: use U I mode while you write, codegen for a first draft, the inspector to step through, and the trace when it fails in C I.
More in this series
1:2412Flaky tests: find the cause, fix it
What a flaky test is, the usual causes (fixed sleeps, shared data, fragile locators, timing), how to fix each one, and why retries are a safety net, not a cure.
1:2113Reports and running tests in CI
Run Playwright on every pull request with GitHub Actions, run tests in parallel across workers and browsers, and keep the HTML report and traces as artifacts.
1:3314Your automation plan
A practical plan for a manual tester becoming automation QA: start with ten smoke tests, build them well, triage failures as product bug, test bug or environment, and grow each sprint.