Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 35 ยท Debugging and Reports

Traces, Videos and Reports

Capture evidence from test runs: Playwright traces, videos and screenshots, Cypress screenshots and Cloud, plus HTML and JUnit reports for your team and CI.

When a test fails on your laptop, you can watch it. When it fails in CI at 3 a.m., nobody is watching, and all you have is whatever the run saved. Good evidence turns "it failed somewhere" into "this request returned a 500 at step four". This lesson covers the artifacts both tools can produce (traces, videos, screenshots) and the reports that collect them.

The real tools produce these files from a live browser, which this site does not have. Commands and configuration are read-only. The runnable examples are Node.js stand-ins: one builds a small trace log and decides when a trace is kept, the other turns results into a JUnit XML report. The real file formats are more detailed than the stand-ins.

Playwright traces

A trace is a recording of a whole test: every action, a DOM snapshot before and after each one, console messages, network requests and the source code line. You open it later in the trace viewer and scrub through it like a video, but with a real, inspectable page at each step.

You choose when to record in the config:

TypeScript
// playwright.config.ts (read-only)
export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  use: {
    trace: 'on-first-retry',
    video: 'retain-on-failure',
    screenshot: 'only-on-failure',
  },
});
trace value Meaning
'off' Never record
'on' Record every test (largest cost)
'retain-on-failure' Record every test, keep the file only if the test fails
'on-first-retry' Record only when a failed test is retried the first time

'on-first-retry' is a popular default: passing tests cost nothing, and a flaky or failing test gets a trace on its second attempt. Open one from the command line or from the HTML report:

Terminal
# read-only
npx playwright show-trace test-results/login-chromium/trace.zip
npx playwright test --trace on        # force tracing for one run

Inside the viewer you get an action list on the left, a timeline across the top, the page snapshot in the middle, and tabs for network, console, source and errors. Clicking an action shows the page exactly as it was, and you can open that snapshot's DOM in developer tools. Because a trace is a self-contained zip file, you can attach it to a bug report.

Videos and screenshots

Playwright can record a video per test (video: 'on', 'off', 'retain-on-failure' or 'on-first-retry') and take a screenshot when a test ends (screenshot: 'only-on-failure'). Take one yourself with await page.screenshot({ path: 'step.png' }), or attach a custom file to the report with testInfo.attach.

Cypress saves a screenshot automatically when a test fails in cypress run (the setting is screenshotOnRunFailure, on by default) and when you call cy.screenshot(). Video recording is a config option (video: true), off by default in current versions. Files go to cypress/screenshots and cypress/videos.

Videos are useful for seeing animations and timing, but they are large and cannot be inspected. A trace is usually more informative. Many teams keep traces for failures and skip videos.

Reports

A reporter turns raw results into something a person or a machine can read.

In Playwright you list reporters in the config and can use several at once:

TypeScript
// playwright.config.ts (read-only)
reporter: [
  ['list'],                                         // readable progress in the terminal
  ['html', { open: 'never' }],                      // browsable report in playwright-report/
  ['junit', { outputFile: 'results/junit.xml' }],   // machine-readable for CI dashboards
],
Terminal
# read-only
npx playwright show-report

The HTML report lists every test with its duration, status, steps (including test.step labels), errors and attached screenshots, videos and traces. The JUnit XML format is understood by almost every CI system (GitHub Actions summaries, Jenkins, GitLab, Azure DevOps), which show failures in their own UI.

Cypress is built on Mocha, so it accepts Mocha reporters:

Terminal
# read-only
npx cypress run --reporter junit --reporter-options "mochaFile=results/out-[hash].xml"

Teams often also use Cypress Cloud (a hosted service, formerly the Dashboard). Runs started with cypress run --record --key <key> upload results, screenshots and videos, and the service adds run history, flake detection and parallelization. It is a paid product with a free tier; check the vendor's pages for current limits. Playwright has no built-in hosted service, but you can publish the HTML report as a CI artifact or to a static site.

A trace log builder

A trace is, at its heart, a list of timestamped events. The stand-in below records events while a fake test runs, then applies the retention modes from the table above to decide whether to keep the trace. It prints a text timeline like a miniature viewer.

Node.js Building a trace and choosing when to keep it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Reading the timeline from the top, you can spot the cause quickly: the POST /api/login returned 500 before the assertion timed out. The assertion line is only the place where the failure surfaced, the lesson from Debugging Failing Tests. Real traces add DOM snapshots and screenshots to each row.

Producing a JUnit report

JUnit XML is a very old but very stable format. A file contains a testsuite element with counts, and one testcase per test, with a failure child for failed ones. The stand-in turns a list of results into that shape. The important detail is escaping: messages contain characters like < and & that would break the XML.

Node.js A tiny JUnit XML reporter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Real reporters work on this principle but include more attributes, such as timestamps, output and attachments.

flowchart LR
  R["Test run"] --> A["Artifacts<br/>trace, video, screenshots"]
  R --> J["Results"]
  J --> H["HTML report"]
  J --> X["JUnit XML"]
  A --> H
  X --> CI["CI summary<br/>and dashboards"]

A run produces artifacts and results; reporters combine them into something people and CI can use.

What to keep in CI

Storing everything costs space and time. A sensible policy: keep the HTML report and traces (or screenshots) for failed tests, upload them as CI artifacts with a limited retention period, and keep JUnit XML for the CI summary. Be careful with what the files contain. Traces and videos capture whatever was on screen and in network requests, so test accounts and fake data are a must: never record real customer information or secrets. How to upload artifacts is covered in Running Tests in CI.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does Playwright's trace: 'on-first-retry' do?

    Passing tests pay no tracing cost, while a test that fails and retries produces a trace of its second attempt.
  2. 2. Why does a trace usually help more than a video?

    A video only shows pixels. A trace lets you inspect the page, requests and logs at each step.
  3. 3. Which format do most CI systems understand for test results?

    JUnit XML is a widely supported format that CI tools can parse to show passed and failed tests.
  4. 4. In the JUnit stand-in, why are characters like < and & replaced before being written into attributes?

    Unescaped markup characters make the XML invalid or change its meaning, so reporters escape them.
  5. 5. What should you be careful about when saving traces and videos from CI?

    Artifacts record what the browser saw and sent. Test data and a retention limit keep sensitive information out.

Summary

  • A Playwright trace records actions, DOM snapshots, network, console and source, and opens in the trace viewer.
  • Set trace, video and screenshot in use; 'on-first-retry' and 'retain-on-failure' balance cost and evidence.
  • Cypress saves screenshots on failure automatically in cypress run; video is optional; Cypress Cloud is a hosted option.
  • Reporters turn results into HTML for people and JUnit XML for CI.
  • Keep artifacts for failed tests with limited retention, and never record real personal data.

Next: Cross-Browser and Mobile Testing