Skip to main content

Reporters: HTML, JSON and JUnit

Why This Matters

A test run produces one set of results, which different readers need in different forms. You want something you can click through. A CI server wants a file it can show in its test tab. A script, or an AI assistant, wants structured data it can read without scraping a terminal. Playwright’s reporters give each reader its own format from the same run, and you configure them once.

What you will learn

  • The four reporters this course uses, and who each one is for
  • What the JSON and JUnit files actually contain
  • The difference between a test’s status and a result’s status

Four reporters, one run

This is the local reporter setup in playwright.config.ts of the example repository:

reporter: [
  ["list"],
  ["html", { open: "never" }],
  ["json", { outputFile: "test-results/results.json" }],
  ["junit", { outputFile: "test-results/junit.xml" }],
],
ReporterForWhere
listyou, while the run is goingthe terminal
htmlyou, after the run: steps, screenshots, tracesplaywright-report/index.html, opened with npm run report
jsonscripts and toolstest-results/results.json
junitCI servers (Jenkins, GitLab, Azure DevOps) and test management toolstest-results/junit.xml

open: "never" stops the HTML report from opening a browser after every failed run. Open it when you want it.

Playwright empties test-results/ at the start of every run. The JSON and JUnit files written there therefore always belong to the last run, never to an older one.

Run it

The unit tests from module 1 need no browser and no network, so they make a quick example:

npx playwright test --project=unit
Running 4 tests using 1 worker

  ✓  1 [unit] › tests/module-1/cart-maths.spec.ts:10:1 › subtotal adds price × quantity for every line (5ms)
  ✓  2 [unit] › tests/module-1/cart-maths.spec.ts:18:1 › total adds 21% tax, like the shop's checkout (5ms)
  ✓  3 [unit] › tests/module-1/cart-maths.spec.ts:23:1 › an empty cart costs nothing (2ms)
  ✓  4 [unit] › tests/module-1/cart-maths.spec.ts:27:1 › parsePrice reads the price as the page shows it (12ms)

  4 passed (572ms)

That is the list reporter. The other three wrote their files:

playwright-report/index.html
test-results/junit.xml
test-results/results.json

JUnit: the oldest format

JUnit XML is decades old and every CI tool reads it. Here is the start of the real file from that run:

<testsuites id="" name="" tests="4" failures="0" skipped="0" errors="0" time="0.571507">
<testsuite name="module-1/cart-maths.spec.ts" timestamp="2026-12-01T20:34:25.539Z" hostname="unit" tests="4" failures="0" skipped="0" time="0.024" errors="0">
<testcase name="subtotal adds price × quantity for every line" classname="module-1/cart-maths.spec.ts" time="0.005">
</testcase>

Every spec file becomes a testsuite, and every test becomes a testcase. Playwright puts the project name in hostname. A failed test gets a <failure> element with the error message. JUnit has no concept of flaky, so a test that passed on a retry shows up as passed. To see flaky tests you need the HTML or JSON report.

JSON: everything, structured

The JSON report has four top-level keys: config, suites, errors and stats. The stats block is the summary of the run:

{"startTime":"2026-12-01T20:34:25.494Z","duration":571.507,"expected":4,"skipped":0,"unexpected":0,"flaky":0}

suites follows the folder structure: files contain specs, specs contain one test per project, and tests contain one result per attempt. One test from the real file, shortened:

{
  "title": "subtotal adds price × quantity for every line",
  "ok": true,
  "tests": [
    {
      "projectName": "unit",
      "expectedStatus": "passed",
      "status": "expected",
      "results": [
        { "retry": 0, "status": "passed", "duration": 5, "errors": [], "attachments": [] }
      ]
    }
  ],
  "file": "module-1/cart-maths.spec.ts",
  "line": 10
}

Note the two different status fields, because this is where most homemade scripts go wrong:

  • A result (one attempt) is passed, failed, timedOut, skipped or interrupted.
  • A test (all attempts together) is expected, unexpected, flaky or skipped. “Expected” means the outcome matched expectedStatus. A test marked with test.fail() that fails is therefore expected too.

A test with two failed attempts and one passed attempt has three results and the status flaky. Each failed result carries its errors. Its attachments list the paths of the screenshot and the trace. Because everything is in there, module 8 builds its CI summary from this file, and so can an AI assistant (lesson 41).

Exercise

  1. Run npx playwright test --project=unit and open all three outputs: npm run report, test-results/results.json and test-results/junit.xml.
  2. In src/cart.ts, change TAX_RATE to 0.2 and run again. Find the failure in each of the three outputs. Which output gives you Expected and Received, and which gives you the source line?
  3. Restore TAX_RATE.
Show suggested answer

The run now has 3 passed and 1 failed: total adds 21% tax, like the shop’s checkout, with Expected: 72.59 and Received: 71.99.

  • HTML: the failed test is at the top with a red mark. It shows the full error, with Expected and Received, and the source lines around cart-maths.spec.ts:20.
  • JSON: stats.unexpected is 1. The test has "status": "unexpected", and its single result has "status": "failed". In errors you find the message (with colour codes) and a location pointing at line 20, column 62.
  • JUnit: the testsuite says failures="1". The testcase holds a <failure> element whose message attribute is only the generic first line. The full error and the code are inside the element.

All three have Expected and Received. HTML and JUnit also show the code around the failing line, as text. Only JSON gives the location as data (file, line, column), which is what a script needs.