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.

For screenshots and other files created during a Playwright Test run, set outputDir in your Playwright configuration. For an individual screenshot saved by test code, pass a path to page.screenshot()—or use testInfo.outputPath() to put it in that test’s output folder. For toHaveScreenshot() visual-comparison baselines, configure snapshotPathTemplate instead.

Choose the setting for the kind of screenshot you mean

Playwright has separate path controls for run artifacts, screenshots your test explicitly writes, and expected images used by visual assertions. Changing the wrong one can leave files in the same place even though the test configuration changed.

What you want to save Use this What it controls
Automatic screenshots and other test-run artifacts outputDir, with use.screenshot set to the desired capture policy The Playwright Test output directory and whether screenshots are captured automatically
A screenshot requested in test code page.screenshot({ path }); optionally testInfo.outputPath() The destination for that explicit screenshot
Expected images for toHaveScreenshot() snapshotPathTemplate The location and naming pattern for visual-comparison snapshot files

The documented default test output directory is test-results, under the directory containing package.json. The output directory is for Playwright Test run files; it is not a universal override for every path accepted by Playwright’s screenshot APIs.

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

Set the directory for automatic Playwright Test screenshots

Set the top-level outputDir in your Playwright configuration to choose a common artifact directory. Set use.screenshot separately to choose when Playwright Test captures screenshots automatically. The documented policies are 'off', 'on', and 'only-on-failure'. Playwright’s configuration guide shows screenshot capture configured with 'only-on-failure'.

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

export default defineConfig({
  outputDir: './screenshots',
  use: {
    screenshot: 'only-on-failure',
  },
});

Save this in the Playwright configuration file used by your test run. If your project uses a different config file, check the command that runs the tests and confirm it selects the file you edited.

Choose the capture policy deliberately

  • 'only-on-failure' captures screenshots when a test fails, which is useful when you want failure evidence without requesting a screenshot for every passing test.
  • 'on' enables automatic screenshots for tests, including passing ones.
  • 'off' disables automatic screenshot capture.

This option determines capture behavior; it does not set the destination directory. Set outputDir for the destination.

Set a project-specific output directory

When only one project needs a different artifact location, set outputDir in that project’s configuration rather than changing the common top-level location. The top-level setting provides the shared default for projects; a project-level setting can provide that project’s location. See the configuration reference for the project configuration shape supported by your installed version.

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

Save an explicit screenshot from test code

Use page.screenshot() when the test itself decides when to take a screenshot. Its path option names the output file. A path passed directly to the screenshot API that is relative is resolved from the current working directory, not from the test file’s directory. That distinction matters when you run tests from a different folder or through a CI job.

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

test('save a screenshot', async ({ page }) => {
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshots/example.png' });
});

Use an absolute path if you need to anchor the destination explicitly, or use the test information helper for a predictable test-specific location.

Prefer testInfo.outputPath() for test artifacts

When a screenshot belongs with the current test’s output, call testInfo.outputPath() and pass its result as the screenshot path. The helper places the file inside that test’s output directory and supports path segments. Playwright documents that paths created with this helper stay inside the test output directory and that parallel tests will not interfere through the helper.

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

test('save a test-specific screenshot', async ({ page }, testInfo) => {
  await page.goto('https://example.com');
  await page.screenshot({ path: testInfo.outputPath('screenshot.png') });
});

This is usually a better choice than writing every test to a shared fixed filename: test output is isolated per test, and parallel workers do not all target the same path. The TestInfo API reference documents the helper’s behavior.

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

Change the directory for toHaveScreenshot() baselines

Visual assertion baselines are expected images used for comparison; do not assume that changing outputDir moves them. Configure snapshotPathTemplate in the test configuration to set their path pattern. The template can use tokens including {testDir}, {testFilePath}, {projectName}, {arg}, and {ext}.

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

export default defineConfig({
  snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
});

In this example, the template groups expected images under a __screenshots__ directory and uses the test file path, assertion argument, and image extension in the generated path. Relative template paths resolve relative to the configuration directory. Check the TestConfig API reference for the supported template tokens and behavior in the Playwright version installed in your project.

Keep assertion paths within the snapshot directory

A path or name supplied to toHaveScreenshot() is subject to snapshot-directory constraints: an assertion path outside the directory for that test can throw. If a baseline does not appear where expected, inspect both the configured template and the path segments or name passed to the assertion. The snapshot assertion reference describes the assertion API and its path behavior.

Understand cleanup, path bases, and parallel tests

The configured output directory is cleaned at run start

Playwright Test cleans its configured output directory at the start of a run, then creates a unique subdirectory for each test. Do not treat outputDir as a general-purpose archive location for files you need to preserve across runs. Store long-lived files outside the directory Playwright cleans, or copy artifacts elsewhere after the run.

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

Relative paths have different bases

  • The documented default test-results directory is under the directory containing package.json.
  • A relative path passed directly to page.screenshot() is resolved from the current working directory.
  • A relative snapshotPathTemplate path is resolved from the configuration directory.
  • testInfo.outputPath() returns a path inside the current test’s output directory.

These bases are not interchangeable. If a file seems to be missing, determine which API wrote it and the working directory, config location, or test output directory that applies to that API.

Parallel tests need distinct destinations

For explicit per-test screenshots, testInfo.outputPath() avoids multiple parallel tests targeting the same test-output filename. If you choose a fixed path instead, design the filename and directory so concurrent tests cannot overwrite one another. Playwright’s per-test output structure is also why automatic artifacts may be found in nested directories rather than directly in the directory named by outputDir.

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

Troubleshoot screenshots saved to the wrong place

  • Automatic screenshots still appear under the default directory: Check that the test command loads the configuration file you edited, and confirm that outputDir is at the intended top-level or project-level scope.
  • No automatic screenshot is created: Check use.screenshot. If it is 'off', automatic capture is disabled; with 'only-on-failure', passing tests do not produce automatic failure screenshots.
  • A manual screenshot is not under outputDir: A direct page.screenshot({ path }) destination is controlled by its own path. Use testInfo.outputPath() to place it in that test’s output folder.
  • A relative screenshot path resolves somewhere unexpected: Direct screenshot paths are relative to the current working directory. Use an absolute path or the test output helper.
  • Visual baselines did not move after changing outputDir: Configure snapshotPathTemplate; it is the setting for baseline paths.
  • A visual assertion throws about its path: Keep the assertion’s path within the snapshot directory for the test and review the configured template.
  • Files disappear between runs: The configured test output directory is cleaned at run start. Move files you need to retain to a separate location.
  • Tests overwrite each other’s screenshot: Avoid a shared fixed filename for parallel tests. Use testInfo.outputPath() for test-specific artifacts.

Check your installed Playwright version

The Playwright Test API reference identifies snapshotPathTemplate as added in v1.28. The available documentation does not establish the latest Playwright package version, so this article does not claim that every detail has been verified against the newest release. If your project is pinned to an older version, confirm the option in the API reference and configuration types for that installed version before adopting it.

Or skip the browser setup

If you need a screenshot of a public webpage rather than an artifact from a Playwright test, ScreenshotNeo provides a website screenshot API. One GET request can return a screenshot or PDF; its consent-banner handling accepts the banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture. Each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. An MCP server exposes screenshot tools to Claude, Cursor, and other MCP clients.

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

Here is a cURL request that saves a WebP screenshot. Replace the access key with your ScreenshotNeo API key; the url parameter is the page to capture. See the ScreenshotNeo API documentation for request options and response details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

For a page you can capture directly with Playwright, use Playwright’s configuration and APIs above. For a screenshot service instead, ScreenshotNeo starts with a free allowance of 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Visit ScreenshotNeo or sign up free for 1,000 screenshots a month, with no card.

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.