A report that helps find the cause
A good report answers three questions: what failed, why, and whether it failed before. Each failure needs the assertion message, a trace, a screenshot or video for failed tests, a correlation id, the build version, the environment and the shard number. Reporting is built in layers for different readers, and raw results (JSON, JUnit XML) are stored apart from the HTML so that history and metrics do not depend on one tool.
System design · Reporting
A test is red. How many minutes does it take to find the cause from the report alone?
The nightly run of 800 tests is over: 14 are red. The report is a list of names, each with "Error: expect(received).toBe(expected)". To understand what happened, the engineer opens CI, looks for artifacts, asks in chat which build it is and guesses which service to search the logs in. Each failure takes twenty minutes, and there is no strength left for a real regression. A report that only lists test colours gives the minimum. A good report answers three questions: what failed, why, and whether it failed before.
How it works and why. Different readers need different detail, so reporting is built in layers, each answering its own question, not one "universal" report. The engineer investigating a failure wants steps, DOM, network and console. The team wants to see a trend: what is unstable, what is slow. The commit author wants a short message "your PR broke this" with a link. Management needs a few numbers over time. The lower layer feeds the upper one, so raw results must be kept in a neutral format.
Four layers of reporting
What every failure needs.
- The assertion message with the stack: which line and which expectation.
- Playwright trace: steps, DOM snapshots before and after an action, network requests, console.
- A screenshot and a video if needed: they take space, so usually only for failed tests.
- The correlation id of the requests, to find backend logs.
- The environment, the build version, the shard number: without these a failure cannot be reproduced.
Example: from a list of reds to a report that explains. A configuration that collects artifacts only where they are needed and puts raw results apart from the HTML:
// playwright.config.ts
export default defineConfig({
reporter: [
['html', { open: 'never' }],
['junit', { outputFile: 'results/junit.xml' }],
['json', { outputFile: 'results/results.json' }],
],
metadata: { build: process.env.BUILD_SHA, env: process.env.TARGET_ENV },
retries: process.env.CI ? 1 : 0,
use: {
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
});
Three reporters give three different outputs: HTML for a person, JUnit XML for CI systems, JSON for your own analytics. The metadata field is included in the reports and serialized into the JSON report, so the build version and the environment are recorded together with the results. With sharding each shard writes a blob report and then they are merged into one:
# on each shard (config has reporter: 'blob' in CI)
npx playwright test --shard=1/4
# after all shards: one HTML report
npx playwright merge-reports --reporter html ./all-blob-reports
One failure in two reports
Only a colour
Test transfer completes
Error expect(received).toBe(expected)
Trace none
Build unknown
Answers the questions
Test transfer completes
Error expected 201, received 500
Trace steps, network, console
Build sha, shard 3/4, staging
Notifications. A message about every failure in a shared channel turns into noise nobody reads within a week. What works is addressing: to the PR author or the area owner, and into the shared channel only failures on main. The message is short: how many failed, the first few names, a link to the report and to the commit.
Limits and alternatives. The built-in Playwright HTML report is good for dissecting one failure but does not keep history between runs: trends need an external store. Here the choice is between ready services (Allure, ReportPortal, runner cloud dashboards) and your own database with JSON results. A ready one starts faster, your own is more flexible. Raw JSON or JUnit XML must be kept in any case: then the choice of a reporting tool does not tie you to it forever.
Common mistakes.
- Storing a video for every test: gigabytes nobody opens. For failed ones it is enough.
- Artifacts live only on the CI agent and vanish when the job ends: they must be uploaded as artifacts.
- A notification for every failure in a shared channel: within a week the channel is muted.
- A report without the build version and the environment: the failure cannot be reproduced.
- Only HTML without raw results: there is nothing to build history and metrics from later.
Check yourself
Why does the config use trace: 'on-first-retry' together with video: 'retain-on-failure' instead of recording everything always?
Answer
Recording a trace and a video costs execution time and space. Tests that passed on the first attempt need no artifacts. on-first-retry gives a trace exactly for a test that failed and was repeated, and the video is kept only for failed ones. So diagnostics exist where they are needed and the rest do not pay for them.
Four shards have finished, each with its own HTML report. How to get one report and why not stitch them by hand?
Answer
Each shard writes a blob report (reporter: 'blob'), and after all shards npx playwright merge-reports --reporter html merges them into one report with correct totals and tests from all shards. Stitching HTML by hand gives wrong counters and loses attachments.