Notes
A real failure
We switched on ShopRung's search case bug, which makes search case sensitive, and ran the mug search test. It failed, and the output already says a lot. The locator, the result count. Expected two products, received zero products. The call log shows the locator was found fourteen times during the five second retry, always with zero products, so this is not a timing problem. It points at line nine, and it saved a trace file.
Error: expect(locator).toHaveText
(expected) failed
Locator: getByTestId('result-count')
Expected: "2 products"
Received: "0 products"
Timeout: 5000ms
Call log:
14 × locator resolved to
<span ...>0 products</span>
> 9 | await expect(page.getBy...
attachment: trace.zip Recording traces
Traces are controlled by the trace setting. On first retry records only when a test is retried, which is cheap and the common default for CI. Retain on failure records every test but keeps only failures. On records everything, useful while debugging. You can also pass trace on from the command line, as we did. In CI, upload the test results and report folders as build artifacts, so anyone can download the trace.
use: { trace: "on-first-retry" }
record only when retried
"retain-on-failure"
record all, keep failed only
"on" always (slow, debugging)
"off"
CLI: npx playwright test --trace on
CI: upload test-results/ and
playwright-report/ as artifacts The viewer
Open the trace with show trace and the file path, or drop it onto the trace viewer web page, which runs locally in your browser. On the left, every action and assertion in order, with timings. In the centre, a real DOM snapshot of the page before, during and after each step; you can inspect it like a live page. Tabs show network calls, console messages, the source line and errors. It is like a flight recorder for the test.
npx playwright show-trace \ test-results/.../trace.zip or drag it onto trace.playwright.dev (runs in your browser) left: each action and assert centre: DOM snapshot, before / action / after tabs: Network, Console, Source, Errors, Attachments
Reading it
Reading our trace. The fill and the click worked. The after snapshot shows results for mug with no cards. The network tab shows the page called get products with q equals mug, and the API answered a count of zero. So the UI displayed exactly what the API returned; the bug is in the search API's case handling. That is a real defect to report, with the trace attached, not a flaky test to re run.
- fill "mug" → click Search
- snapshot: page says "Results for “mug”", 0 cards
- Network: GET /api/products?q=mug → {"count": 0, "items": []}
- so: the UI is fine; the API search is wrong (case) → a real bug, raise it against the search API
Other evidence
Other evidence. Screenshot only on failure and video retain on failure add pictures and recordings to the report. Recent Playwright versions also write an error context file for each failure: the error, the call log and a text snapshot of the page's accessibility tree. It is designed to be pasted into an AI assistant or a bug report, and Part eleven builds on that idea.
use: {
screenshot: "only-on-failure",
video: "retain-on-failure",
}
error-context.md (written on
failure): the error, the call
log and a page snapshot
(accessibility tree as text)
ready to paste into an AI
assistant or a bug report The inspector
To debug live, run with debug. The inspector opens with the test paused before the first step, and you step over actions one by one while the target element is highlighted in the browser. To stop at one place, put await page pause in the test. UI mode, from the last episode, combines a runner, the timeline and a locator picker, and it re runs tests when you save.
npx playwright test --debug opens the Inspector, paused step over each action highlights the locator target await page.pause(); pause at this line only UI mode (--ui): pick locator, watch mode, timeline
Pick a locator
The pick locator button lets you hover over any element and see the locator Playwright would use. It follows the same priority as the locators episode: role and name first, then labels, text and test ids, CSS last. It is a fast way to learn and a good starting point. You still decide whether it is stable, matches exactly one element, and describes meaning rather than position.
- hover an element in the inspector or UI mode
- it suggests the best locator it can find, in priority: role + name, label, text, test id, then CSS
- you still decide: is it stable? exactly one match? meaningful?
Codegen
Codegen opens a browser and a code window side by side. Run it with ShopRung's address, then use the shop normally: search for mug, open a product, log in. Each action appears as code with good locators. The toolbar can add assertions for visibility, text or values by clicking an element. It is great for exploring a new page, learning the API, and getting a first draft quickly.
npx playwright codegen \
http://localhost:8080
you click and type, it writes:
await page.getByRole("searchbox",
{ name: "Search products" })
.fill("mug");
await page.getByRole("button",
{ name: "Search" }).click();
toolbar: add assertions
(visible, text, value) Its limits
But a recording is a draft, not a finished test. It has no data reset, logs in through the UI every time, has few assertions, and repeats the same locators in every file. Turn recordings into real tests: set up data through the API and fixtures, move locators into page objects or helpers, and add specific assertions about the behaviour you care about. Record to start; engineer to finish.
- recordings have: no reset or test data logins in every test few or no assertions repeated locators
- turn them into: API setup + fixtures page objects or helpers clear, specific expects
Common mistakes
Debugging mistakes. Re running a failed test until it passes instead of reading the trace. Traces turned off in CI, or recorded but never uploaded, so they vanish with the machine. Tracing every test on every run, which is slow and produces huge artifacts. Committing page pause or test only. And shipping raw codegen output as if it were a finished suite.
- re-running until green instead of reading the trace
- traces off in CI
- not uploading artifacts
- trace "on" for every CI run (slow, huge)
- committing page.pause()
- shipping raw codegen output
Say it like this
In the interview: first I read the error and call log: expected versus received, and whether the locator was missing or the value was wrong. Then I open the trace: DOM snapshots, network calls and console. I decide whether it is a product bug, a test bug or an environment problem. Product bugs are reported with the trace attached. Our CI records traces on first retry and uploads them as artifacts.
- "Read the error and call log: expected vs received, and whether it was waiting or wrong. Open the trace: DOM
- snapshots, network, console.
- Decide: product bug, test
- bug or environment. Report
- bugs with the trace. CI keeps
- traces on first retry and uploads them as artifacts."