Playwright HTML Reporter: Beyond the Defaults, for Agents

Most teams turn on Playwright's HTML reporter, glance at the red and green summary, and stop there. The reporter does more: it shows traces, screenshots, video and custom attachments per test, and Playwright can emit the same results as structured JSON that almost nobody queries. Those are the places where triage gets faster or slower.

The defaults are tuned for a developer running tests locally, not for CI artifact pipelines, sharded runs or team dashboards. Agentic quality engineering adds another reader. Coding agents now write and repair Playwright tests and read the results to decide what to change, and a trace or attachment that explains a failure helps an agent as much as a person. A bare "timed out" does not.

This article covers what the reporter produces, how to add attachments and metadata, how to merge sharded reports, how to route structured results into a queryable store, the configuration mistakes that make the reporter feel like overhead, and how to make its output useful to agents without letting agents game it.

Build an API Automation Framework With Node.js

Learn Node.js, Cucumber, GitHub Copilot, APIs, CI/CD, and modern automation by building a complete framework.

Learn more

What Playwright's HTML Reporter Actually Produces

Playwright's HTML reporter generates a self-contained playwright-report/ directory containing an index.html entry point plus the trace files, screenshots and video it links to when those are enabled. The data inside the HTML report is an internal format, so for anything you want to query, add Playwright's JSON reporter alongside it (['json', { outputFile: 'results.json' }]): it carries every test result, attachment path, error message, retry and timing in a documented structure. That JSON is the artifact to build on; the HTML is the view for people.

In a modern test architecture, the HTML reporter sits at the boundary between execution and observability. It's the last mile before results either get archived and forgotten or get ingested into something queryable — ClickHouse, BigQuery, PostgreSQL, or a purpose-built platform like Buildkite Analytics or ReportPortal. Teams that treat the HTML file as the terminal artifact are implicitly choosing not to track trends, not to correlate failures across branches, and not to alert on regressions. That's a deliberate trade-off worth naming explicitly.

Extending the Reporter: Attachments, Metadata, and Shard Merging

The highest-value customization is attaching structured metadata to individual tests at runtime. Playwright's testInfo.attach() API accepts arbitrary buffers or strings, so you can embed request/response payloads, feature flags in effect, or environment fingerprints directly into the report — no external log correlation required.

// In any test file
test.afterEach(async ({ page }, testInfo) => {
  // status is only known after the test body has finished
  if (testInfo.status !== testInfo.expectedStatus) {
    const state = await page.context().storageState();
    await testInfo.attach('storage-state', {
      body: JSON.stringify(state),
      contentType: 'application/json',
    });
  }
});

test('checkout flow', async ({ page }, testInfo) => {
  const flags = await getFeatureFlags(); // your internal call
  await testInfo.attach('feature-flags', {
    body: JSON.stringify(flags, null, 2),
    contentType: 'application/json',
  });

  // ... test body ...
});

Conditional attachment on failure keeps artifact size sane on large suites. With the JSON reporter enabled, each attachment is listed under the test result's attachments, queryable without opening a browser.

Merging Sharded Reports in CI

Sharding is where most teams hit their first real pain point. Running --shard=1/4 through 4/4 produces four independent report directories; the default HTML reporter has no awareness of siblings. Playwright 1.37+ ships merge-reports for exactly this:

# GitHub Actions — merge step after matrix shards complete
- name: Merge Playwright reports
  run: |
    npx playwright merge-reports \
      --reporter=html \
      ./all-blob-reports
  # Each shard must upload with: --reporter=blob
  # and artifacts collected into ./all-blob-reports before this step

The critical detail: shards must run with --reporter=blob, not html. The blob reporter writes a binary .zip per shard; merge-reports reassembles them into a single coherent HTML report with correct retry attribution across machines. Teams that skip this and try to concatenate JUnit XML from shards lose trace attachments and get duplicate test IDs.

Routing JSON Results Into a Queryable Store

Once the JSON reporter's output exists (merge-reports can also produce it from blob reports with --reporter=json), it is worth ingesting. A minimal Python script can parse it and upsert into PostgreSQL, giving you a queryable history without a full platform purchase:

import json, os, psycopg2, sys

report = json.load(open(sys.argv[1]))  # results.json from the JSON reporter

conn = psycopg2.connect(os.environ["TEST_DB_DSN"])
cur = conn.cursor()

def walk(suite):
    # describe() blocks appear as nested suites
    yield from suite.get("specs", [])
    for child in suite.get("suites", []):
        yield from walk(child)

for top in report["suites"]:
    for spec in walk(top):
        for result in spec.get("tests", []):
            for run in result.get("results", []):
                cur.execute("""
                    INSERT INTO playwright_results
                      (title, status, duration_ms, retry, run_at)
                    VALUES (%s, %s, %s, %s, NOW())
                    ON CONFLICT DO NOTHING
                """, (
                    spec["title"],
                    run["status"],
                    run["duration"],
                    run["retry"],
                ))
conn.commit()

Once results are in PostgreSQL, a Grafana panel querying P95 duration by test title over a 14-day window makes slow-test regression visible before it becomes a pipeline-blocking event. Keeping traces and structured metadata in the same artifact, rather than scattered across Slack threads and separate log systems, also shortens triage.

Configuration Mistakes That Erode Reporter Value

The most common mistake is enabling trace: 'on' globally in CI without understanding the storage cost. A large suite with video and full trace on every test produces very large artifacts per run. Teams hit storage limits and quietly disable the feature rather than switching to trace: 'on-first-retry' or 'retain-on-failure', the two settings that give you trace coverage where you need it while keeping artifacts small. This is a mental-model problem: trace is treated as an all-or-nothing toggle rather than a conditional signal.

The second mistake is ignoring the outputFolder and open config keys in CI contexts. Leaving open: 'on-failure' (the local default) in a CI playwright.config means the process tries to spawn a browser to display the report and hangs or errors on headless runners. Explicitly set reporter: [['html', { open: 'never', outputFolder: 'playwright-report' }]] in your CI config. Similarly, teams that run each browser project (e.g., Chromium, Firefox, Mobile Safari) as a separate CI invocation without a distinct outputFolder per invocation silently overwrite reports, losing cross-browser failure data. A single run with several projects produces one combined report.

Making the report useful to coding agents, and keeping it honest

When a coding agent is fixing a failing Playwright test, it rarely opens the HTML report; it reads the terminal output, the JSON results and any attachments it can reach. Three habits make those inputs useful.

  • Attach the evidence as text. Alongside screenshots, attach the failing request and response, or a short DOM excerpt around the target element, as JSON or plain text with testInfo.attach(). A model can read text; a screenshot alone often leaves it guessing at the selector.
  • Keep traces on failure. With trace: 'retain-on-failure', a person reviewing an agent's fix can open the trace for the original failure and check that the fix addresses what actually happened.
  • Record retries per result. The retry field in the JSON results shows whether a test passed only after a retry. Store it, and check agent pull requests for passes that depend on retries.

The common ways agents make a Playwright test pass without fixing it are easy to detect in a diff: raising retries or timeout in playwright.config, adding page.waitForTimeout(), or adding test.skip or test.fixme. Flag those in review, and write the rule into a repository instruction file such as .github/copilot-instructions.md: use web-first assertions such as await expect(locator).toBeVisible() and role-based locators, never fixed waits.

git diff origin/main...HEAD -- '*.spec.ts' 'playwright.config.*' \
  | grep -E '^\+.*(waitForTimeout|test\.skip|test\.fixme|retries:|timeout:)' \
  && echo "::warning::Retry, timeout, wait or skip change: review by hand"

If the application includes an AI feature, tag those tests (for example with @llm in the title and --grep) and report their pass rate over several runs rather than reading a single result. The retry count article explains why retry-dependent passes inflate the numbers.

What Teams Misread About the HTML Reporter's Role

The most persistent myth is that the HTML report is the observability layer. It isn't — it's a point-in-time artifact for a single run. Trend detection, flakiness scoring, and pattern detection across test history require a persistent store that the HTML reporter alone cannot provide. Teams that build a Grafana dashboard on top of ingested JSON results get trend observability; teams that just archive HTML files get a searchable archive of individual runs with no cross-run signal. These are fundamentally different capabilities, and confusing them leads to "we have Playwright reporting" being treated as equivalent to "we have test observability."

A related misread is treating retry counts in the report as noise to suppress. Playwright surfaces retry per result explicitly; that number is a direct input to flakiness detection and should be stored and trended, not hidden. A test that passes on retry 2 every Tuesday is telling you something about infrastructure state or test isolation — suppressing the retry count in your dashboard means you'll never see the pattern. Wire it into your ingestion pipeline from day one.

Playwright's HTML reporter is more capable than most teams use it. The practical next step: switch sharded CI runs to --reporter=blob, add merge-reports as a post-matrix step, and load the JSON reporter's output into a table you can query. From there, a Grafana panel showing P95 duration and retry rate by test title will surface more signal in a week than months of scanning HTML archives. If you're building out the broader CI metrics layer, the observability metrics beyond flaky tests article covers what to instrument next.

Note: This article is for informational purposes only and is not a substitute for professional advice. If you need guidance on specific situations described in this article, consider consulting a qualified professional.

Understanding how systems actually work is the first step toward navigating them effectively.

Browse all articles