The trace viewer
Why This Matters
In CI nobody watches the browser. When a test fails there, all you have is what the run recorded. A screenshot shows the end state; a trace shows the whole story: every action, a snapshot of the page at each step, every network request and every console message. It is UI mode for a run that already happened.
When Playwright records a trace
The example config says:
use: {
trace: "on-first-retry",
screenshot: "only-on-failure",
},
and retries: process.env.CI ? 2 : 0. In CI a failing test is retried, and the first retry is recorded. A test that passes first time costs nothing; a failing one leaves a full trace behind.
Locally there are no retries, so force a trace when you need one:
npx playwright test tests/module-3 --project=chromium --trace on
Open a trace
Traces end up in test-results/<test name>/trace.zip. Open one with:
npx playwright show-trace test-results/<test name>/trace.zip
or open the HTML report (npm run report) and click the trace icon next to a failed test. You can also drag a trace.zip onto trace.playwright.dev; it is processed in your browser.
Read it in order
- Errors tab: the failure, exactly as in the terminal.
- The failing step in the action list: look at the snapshot before it. Was the element there? Was the page still loading?
- Network: which requests were made, how long they took, what came back.
- Console: errors the page itself logged.
For the slow-backend test on the exercise branch, the error says only that no product became visible within 5000 ms. The Network tab says why: the products request had not even returned yet.
Get a trace from CI
The repository’s workflow runs on every branch, including the exercise branches. Those runs are red on purpose: the branches exist to give you something broken to investigate. Every run ends with one artifact for people:
- uses: actions/upload-artifact@v7
with:
name: playwright-report
path: |
playwright-report/
test-results/results.json
test-results/junit.xml
On GitHub, open the failed run under Actions and download playwright-report at the bottom of the run summary. Unzip it and run npx playwright show-report playwright-report: the traces open from the report, just like locally. In CI the config records a trace on the first retry (trace: "on-first-retry"), so every failed test has one. Module 8 shows how this report is built from several machines.
Exercise
The exercise/debugging branch fails in CI. Open the repository’s Actions tab, download the report of the latest run on that branch, and open the trace of the shop still shows products when the API is slow. How long did the products request take, and what is the root cause: the product, the test, or the environment?
Show suggested answer
The products request takes about six seconds, because the test itself delays it with page.route, simulating a slow backend. The assertion gives up after the default 5 seconds. The shop works correctly; it is just slower than the test allows. That is an environment problem, not a product bug and not really a test bug either. The fix is to decide how long this test should wait and say so explicitly, for this one assertion:
await expect(page.getByTestId(/^product-\d+$/).first()).toBeVisible({ timeout: 15_000 });
Raising the global timeout instead would make every other test slower to fail.