Playwright Trace Viewer

An airplane carries a flight recorder that stores every reading until investigators need them. The Playwright trace viewer works like that recorder for tests. It stores each action, screenshot, network call, and console message, so an engineer can replay a failure step by step long after the test ends.

What a Trace Contains

trace.zip
   |
   +-- Timeline of every action
   +-- Snapshot before and after each step
   +-- Network requests and responses
   +-- Console messages and errors
   +-- Source code of the test

Turning Tracing On

The config file controls when Playwright records traces.

export default defineConfig({
  use: {
    trace: 'on-first-retry',
  },
});
  • off records nothing.
  • on records every test.
  • retain-on-failure keeps traces for failed tests only.
  • on-first-retry records when a failed test runs a second time.

Recording every test consumes disk space and time. The on-first-retry and retain-on-failure choices keep costs low.

Recording From the Command Line

npx playwright test --trace on

Opening a Trace

npx playwright show-trace test-results/login-chromium/trace.zip

The HTML report links to the trace of each failed test.

The Viewer Layout

+-------------------------------------------------------+
| Actions list     |  Page snapshot (before / after)    |
|                  |                                    |
| goto /login      |   [ screenshot of the page ]       |
| fill Email       |   highlighted target element       |
| fill Password    |                                    |
| click Sign in  X |                                    |
+------------------+------------------------------------+
|Tabs: Call | Log | Errors | Console | Network | Source |
+-------------------------------------------------------+

Reading a Failure

Click the failed action in the list. The snapshot shows the page at that moment, with the target element outlined. The Errors tab shows the message, and the Network tab shows failed requests. A hidden button, a covered element, or a server error usually becomes obvious within a minute.

Travelling Through Time

The timeline at the top lets a person drag across the run. The snapshot panel updates to match the chosen moment. The viewer shows a fully interactive copy of the page, so the person can inspect elements with the browser developer tools.

A Real-World Scenario

A checkout test passes on every laptop and fails once a day on the CI server. Logs show only a timeout. The team enables on-first-retry tracing and downloads the trace from the next failure. The Network tab reveals a payment request that returned a 502 error. The team reports the server problem to the right group within the hour.

Habits for Better Traces

  • Upload trace files as CI artifacts so everyone can download them.
  • Keep sensitive data out of test pages, because traces store page content.
  • Delete old traces on a schedule to save storage.

Quick Practice Task

Set trace to on, run one test, and open the generated trace.zip with show-trace. Click three different actions and compare the before and after snapshots.

Common Questions

Do traces slow down tests?

Slightly. Recording adds some overhead, which explains why teams limit tracing to retries or failures.

Can a colleague open my trace?

Yes. The zip file travels by email or CI artifact. Remember that it contains page content, so share it only with trusted teammates.

Where do traces live after a run?

Each trace sits inside the test-results folder next to its test. The HTML report links to the same file.

Key Takeaways

  • A trace records actions, snapshots, network calls, and console output.
  • The on-first-retry mode balances detail against cost.
  • The viewer replays a failure without rerunning the test.
  • CI failures become easier to diagnose with saved traces.