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

Use Playwright Test’s snapshotPathTemplate setting. Point it at one root directory, then keep {testFilePath} and {arg} in the template so every baseline remains traceable to its test and screenshot name:

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

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

This stores all visual-regression references below tests/__screenshots__, while preserving each test file’s path and each assertion’s name. Add {/projectName} when browser projects need separate baselines.

Configure one snapshot root

snapshotPathTemplate controls where Playwright Test writes and reads screenshot references created by toHaveScreenshot(). It was added in Playwright 1.28. Relative template paths are resolved from the directory containing your Playwright configuration file.

Recommended layout

Create or edit playwright.config.ts:

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

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

With a project rooted at /repo, a test at tests/account/profile.spec.ts, and an assertion named profile-page.png, Playwright places the reference under a path equivalent to:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
/repo/tests/__screenshots__/account/profile.spec.ts/profile-page.png

The exact filename extension is supplied by {ext}. The default screenshot format is PNG; an explicit WebP name is also supported and remains lossless according to Playwright’s visual-comparison guidance.

Why retain the test-file path?

A single flat directory such as tests/__screenshots__/{arg}{ext} is easy to write but causes collisions when two test files both use home.png. Keeping {testFilePath} makes ownership visible and lets teams reuse short, meaningful assertion names safely.

Understand the template tokens

The template is a path pattern. Playwright substitutes tokens when it resolves a snapshot filename.

Token What it represents Why you might use it
{arg} The screenshot argument, such as landing from toHaveScreenshot('landing.png') Preserves the name chosen in the test.
{ext} The resulting image extension Lets the same template support PNG or WebP.
{testDir} The configured test directory Places the shared root alongside your tests.
{testFilePath} The test file’s path relative to the test directory Prevents name collisions and shows ownership.
{testFileDir} The directory containing the test file Useful when you want a layout close to each test.
{testFileBaseName} The test filename without its extension Creates a compact, file-oriented hierarchy.
{testFileName} The test filename including its extension Retains the original filename in a path.
{testName} The test’s title Can make paths descriptive, but titles containing path separators need care.
{platform} The execution platform value Separates references when platform-specific rendering is intentional.
{projectName} The configured Playwright project name Keeps browser or device projects from sharing incompatible baselines.
{snapshotDir} The snapshot directory calculated by Playwright Useful when composing a template around Playwright’s derived directory.

Tokens can be combined. The optional slash form {/projectName} includes both the slash and project name only when a project name has a value, avoiding an empty directory segment for an unnamed project.

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

Add screenshot assertions to your tests

Visual-regression references are generated by Playwright Test assertions, not by arbitrary screenshots saved with page.screenshot({ path }). A minimal test looks like this:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import { test, expect } from '@playwright/test';

test('landing page', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('landing.png');
});

On the first run, Playwright captures the image and writes the reference into the configured template location. On subsequent runs, it captures the page again and compares the result with that file. You can also compare a locator rather than the whole page:

test('navigation header', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page.locator('header')).toHaveScreenshot('header.png');
});

Use explicit names when a test contains multiple assertions. Names such as desktop.png and mobile.png communicate intent and become the {arg} portion of the path.

Keep projects’ baselines separate when needed

Projects commonly represent Chromium, Firefox, WebKit, mobile device profiles, or different themes. If those projects render differently, give each one its own reference tree:

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

export default defineConfig({
  testDir: './tests',
  snapshotPathTemplate:
    '{testDir}/__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'mobile',
      use: { ...devices['iPhone 13'] },
    },
  ],
});

The resulting tree has separate chromium and mobile branches below __screenshots__. Use the project token when differences are expected; do not add it merely because a project exists if all projects are deliberately required to share one rendering baseline.

Generate, update, and review references

Create references on the first run

Run the relevant test normally:

npx playwright test tests/landing.spec.ts

If no reference exists, Playwright writes one under the configured directory. Treat that first capture as a proposed baseline: inspect it before committing.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Refresh references after an intentional UI change

When a reviewed product change should alter the expected image, regenerate references with:

npx playwright test --update-snapshots

Limit the command to a file, project, or test title when you want a smaller update. Review the resulting image diffs and commit only the references that match the approved change. Do not use the update flag to hide an unexpected regression.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Commit the reference tree

Add the configured __screenshots__ directory to version control. Keeping references beside the test suite gives code review a durable before-and-after record and allows CI to compare against the same files used locally.

Find a calculated snapshot path in code

If tooling needs to locate a reference rather than guessing the directory, ask Playwright for the resolved path:

const reference = test.info().snapshotPath('header.png', {
  kind: 'screenshot',
});
console.log(reference);

The returned path honors your snapshotPathTemplate, project name, test-file path, and extension. This is safer than concatenating __screenshots__ manually.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Make baselines reproducible

A reference image is only useful when the capture environment is stable. Playwright warns that browser rendering can vary with the host operating system, browser version, settings, hardware, power source, headless mode, and other factors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Generate and compare references with the same browser version used by CI.
  • Use the same operating-system image for baseline creation and verification when pixel-level consistency matters.
  • Keep viewport, device scale factor, color scheme, locale, timezone, and font availability consistent.
  • Wait for the page state your test actually intends to verify; otherwise a late-loading image or font can create noise.
  • Review diffs before accepting updates, especially after dependency or browser upgrades.

If your team intentionally supports multiple rendering environments, model each meaningful environment as a named project and include {/projectName} in the template.

Choose a layout that fits your repository

Template Result Best use
{testDir}/__screenshots__/{testFilePath}/{arg}{ext} One shared root, then test-file path and screenshot name Most teams; avoids collisions while keeping one browsable tree.
{testDir}/__screenshots__{/projectName}/{testFilePath}/{arg}{ext} Shared root with optional project directory Distinct browser, device, or theme baselines.
{testDir}/__screenshots__/{arg}{ext} Flat directory Only when every screenshot name is globally unique.
{testFileDir}/__screenshots__/{arg}{ext} References near each test file Small suites that prefer local ownership over a single central tree.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

“The screenshot is not in my folder”

Confirm that the test is using expect(...).toHaveScreenshot(), not page.screenshot({ path }). Then check that the configuration file being loaded is the one containing snapshotPathTemplate. Run with an explicit config if your repository has multiple configurations.

Two tests overwrite one another

The template is probably missing {testFilePath}, or both assertions use the same name within one path. Add the test-file token and give each assertion a distinct filename.

An empty project directory appears

Use {/projectName} rather than a literal slash followed by {projectName}. The optional-slash form omits the segment when no project name is defined.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

References differ only in CI

Compare the CI browser version, operating system, fonts, viewport, device scale factor, headless mode, and power-related environment with the machine that created the references. Align them or maintain separate named projects for environments whose differences are intentional.

Updating snapshots changes too many files

Run the update command against the specific test file or project, inspect the diff, and revert unrelated files. A broad update can accidentally approve regressions across the suite.

The expected file extension is unexpected

Check the assertion filename and {ext} in the template. The extension is derived from the screenshot argument; the default is PNG, while WebP can be selected explicitly.

Performance, repository, and CI practices

  • Keep the shared root in the repository unless your organization has a deliberate artifact-storage policy; Playwright’s comparison workflow expects references to be available to the test run.
  • Run only the affected project during local development, then run the complete matrix in CI.
  • Use stable test data and deterministic animation or time handling so image differences represent UI changes rather than changing content.
  • Review image diffs as part of the pull request, not after merging.
  • When upgrading Playwright or browsers, regenerate references in a controlled change and record which project produced them.

Or skip the browser setup

If you need a clean screenshot of a URL rather than Playwright-managed visual-regression baselines, ScreenshotNeo provides a single-request screenshot API. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers.

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.

See the ScreenshotNeo API documentation for request parameters. Replace the example URL with the page you want to capture.

cURL

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

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Its options include full-page and element capture, dark mode, device presets or custom viewports, retina scale, PDF controls, custom CSS and JavaScript, clicks and waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan. Create a free ScreenshotNeo account to try it.

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.

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