Playwright · Reliable end-to-end tests
What is a Playwright trace and how do you use it?
Short answer
A trace records actions, DOM snapshots, network activity, console logs and screenshots. Open it in the trace viewer to step through a failure; enable it on first retry for low overhead.
A trace is a flight recorder for a test. It captures each action with a before-and-after DOM snapshot, plus network requests, console messages and source locations. The trace viewer lets you move through time, inspect the DOM at each step and see exactly what the page looked like when an action failed.
use: {
trace: "on-first-retry",
screenshot: "only-on-failure",
},await context.tracing.start({
screenshots: true,
snapshots: true,
sources: true,
});
await page.goto("/checkout");
await page.getByRole("button", { name: "Pay" }).click();
await context.tracing.stop({ path: "trace.zip" });What the trace viewer shows
- A timeline of actions with pass and fail states
- DOM snapshots that can be inspected at each step
- Network requests with status, timing and payloads
- Console messages and page errors
- Source locations for the test code that triggered each action
Run npx playwright show-trace trace.zip to open a trace, or use the HTML report where failed tests link to their traces. Record traces on failure in CI and upload them as artifacts, but be aware that traces can contain user data and request bodies.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does trace on-first-retry record?
- 2How do you open a trace file?
- 3What is inside a DOM snapshot?
- 4Why can traces contain sensitive data?
Say it in the interview
A trace records actions, DOM snapshots, network traffic, console output and source locations. I usually set trace to on-first-retry so normal runs stay fast but a flaky failure has evidence. I open it with the trace viewer and step through the DOM and network around the failing action. Traces can include request bodies and credentials, so I treat them as sensitive artifacts.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.