Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To generate a Playwright HTML report with failure screenshots, set screenshot: 'only-on-failure' and configure the HTML reporter in playwright.config.ts. Then run npx playwright test --reporter=html and open the result with npx playwright show-report. Add a trace on retries when you need more than a still image to understand a failure.

Generate and open a Playwright HTML report

Playwright’s HTML reporter creates a folder containing a report that can be served as a web page. The report covers the tests in a run, including their browsers and durations. Generate it from your project directory:

  1. Run npx playwright test --reporter=html.

  2. After the run, open the report with npx playwright show-report.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The default report folder is playwright-report. The HTML report is a run-level view; screenshots and other test artifacts are stored with the test output, typically in test-results. Keep those locations distinct when you collect or publish artifacts from CI.

Choose when the report opens

For a local run, opening the report automatically can be convenient. In CI, set the HTML reporter’s open behavior to 'never' so a test run does not try to open a browser. This setting affects report opening, not screenshot capture.

import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [['html', { open: 'never' }]],
});

The reporter also supports a title, output folder, host, port, and attachments base URL. Use those options when your report needs a different label, destination, serving address, or attachment location. The precise values should match how your team serves and retains the report; the default output folder is sufficient for the basic workflow.

Capture screenshots only when tests fail

Set the use.screenshot option in playwright.config.ts. Its supported values are 'off', 'on', and 'only-on-failure'. For failure evidence without taking a screenshot for every test, use 'only-on-failure':

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [['html', { open: 'never' }]],
  use: {
    screenshot: 'only-on-failure',
    trace: 'on-first-retry',
  },
});

This configuration pairs a failure screenshot with a trace on the first retry. Screenshots, videos, and traces normally go in the test output directory, typically test-results. The HTML report provides the run overview; use its test entries to inspect the available failure evidence.

Choose the capture scope

  • 'off' disables automatic screenshot capture.

  • 'on' captures screenshots for tests, which creates more image artifacts to store and review.

  • 'only-on-failure' focuses automatic screenshots on failed tests, a practical setting when the goal is diagnostic evidence rather than a picture from every successful run.

These modes express a trade-off: broader capture gives more visual records, while failure-only capture limits artifacts to cases that need investigation. Decide based on how much test output your team intends to retain and inspect; no universal retention period or artifact-size figure is provided.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Attach a deliberate screenshot to a test

Automatic failure screenshots are not the only option. When a test needs a particular image—such as a screenshot taken at a meaningful point in its flow—save it under that test’s output path and attach it through TestInfo.attach. Include the PNG content type so report tooling can identify it as an image:

import { test, expect } from '@playwright/test';

test('attach a page screenshot', async ({ page }, testInfo) => {
  await page.goto('https://example.com');

  const screenshotPath = testInfo.outputPath('screenshot.png');
  await page.screenshot({ path: screenshotPath });
  await testInfo.attach('page screenshot', {
    path: screenshotPath,
    contentType: 'image/png',
  });

  await expect(page).toHaveTitle(/Example/);
});

Use the attachment approach when the image should be an explicitly named part of a test’s evidence. It differs from configuring automatic failure screenshots: the test itself decides when to take and attach the image. Reporters can use the content type to display the attachment appropriately.

Use traces when a screenshot is not enough

A screenshot records a visual state, but it does not explain the sequence that produced it. A trace offers more debugging context: Trace Viewer can show action snapshots, logs, source locations, network information, metadata, and attachments. Configure trace: 'on-first-retry' when you want that evidence for a retry without asking for a trace on every initial attempt.

The HTML report links to the trace for a test when one is available. Open that trace in Trace Viewer to move through the actions and inspect what the page and test were doing around the failure. For visual-regression review, trace attachments can also show expected images, actual images, and image diffs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose evidence for the debugging question

Publish the report and preserve its artifacts

The report folder can be served locally as a web page or retained as a CI artifact. In a CI workflow, run the tests, collect the generated report folder and test output directory, and make both available to the people investigating the run. The report is the navigable test summary; the output directory is where screenshot, video, and trace files normally appear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan artifact retention around the way your team works. Screenshots on every test, failure-only screenshots, traces, and manually attached files produce different sets of evidence. Retaining less can reduce the material available for later debugging; retaining more means more files for your CI system to keep. No fixed storage cost, artifact-size limit, or retention duration is established here, so those depend on your CI provider and team policy.

Report serving options

For an immediate local review, use npx playwright show-report. For a shared report, publish the report folder through your CI artifact mechanism or serve it as a web page. The HTML reporter supports configuration for its output folder, host, port, and attachments base URL, which can help align generation with a hosting setup. Ensure that any separately hosted attachments remain reachable from the report; a report page without its referenced evidence is less useful for debugging.

When choosing a CI reporting or test-observability service, check whether its artifact handling fits your team’s report, screenshot, trace, and attachment workflow. This article does not rank third-party CI providers or establish their retention policies.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot missing reports and screenshots

Or skip the browser setup

Playwright screenshots are the right choice for evidence tied to a test’s execution, retries, and trace. For a separate task—capturing a webpage by URL without setting up a browser—ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request can return a PNG, JPEG, WebP, or PDF. Its clean-shot workflow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for AI agents, including Claude, Cursor, or any MCP client.

For the complete request options and API details, see the ScreenshotNeo documentation. This cURL example captures a URL and writes the returned image to a file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Use your API key in place of YOUR_API_KEY. This URL-based capture is an alternative for standalone webpage screenshots; it does not replace Playwright’s test-run screenshots or trace evidence.

ScreenshotNeo’s Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan, and yearly billing gives two months free. Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I inspect a previous Playwright HTML report without rerunning tests?

Yes. Run npx playwright show-report for the existing report.

Can Playwright report visual-regression image comparisons?

Trace Viewer attachments can include expected images, actual images, and image diffs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.