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.

Choose the snapshot assertion that matches what you need to protect: toHaveScreenshot() for rendered pixels, toMatchAriaSnapshot() for accessible structure, or toMatchSnapshot() for text and other values. Add the assertion, run the test to create the initial expected artifact, inspect it, and commit it. Playwright compares later runs with that saved expectation.

Choose the right kind of snapshot

“Snapshot template” can mean different things in Playwright. Pick the assertion based on the output you want the test to protect; a screenshot baseline is not interchangeable with an accessibility-tree or text snapshot.

What you want to check Use What is compared
Visual rendering await expect(page).toHaveScreenshot('landing.png') A captured image against a reference screenshot.
Accessible structure await expect(page).toMatchAriaSnapshot(`...`) The page or locator’s accessibility tree against a textual template.
Text or another value expect(value).toMatchSnapshot('name.txt') A serialized value against a saved snapshot.

Use a screenshot assertion to catch layout, color, or other pixel-level changes; an ARIA snapshot to express expected accessible roles, names, and relationships; and a generic value snapshot for text or other data. For a visual assertion, Playwright’s screenshot comparison API is part of Playwright Test. See the visual comparisons guide and the ARIA snapshot guide.

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

Create a visual screenshot baseline

Add a named screenshot assertion to a Playwright Test test. If no expected image exists, the first run writes a reference screenshot. Treat that run as baseline creation: inspect the image and commit it with the test so later runs have a meaningful expectation.

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
import { test, expect } from '@playwright/test';

test('landing page visual baseline', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveScreenshot('landing.png');
});

Run the test using your project’s normal Playwright Test command, for example npx playwright test. On the first run, check the output to confirm that Playwright wrote the expected screenshot. On subsequent runs, the assertion compares the current rendering with the baseline and reports differences.

Limit the assertion to a component

If a whole-page image would include unrelated or frequently changing content, scope the screenshot to a locator. This makes the expected image correspond to the component you care about.

await expect(page.getByRole('navigation')).toHaveScreenshot('navigation.png');

Choose a stable locator that identifies the intended region. If the locator is missing or resolves ambiguously, fix the test’s targeting before accepting a baseline; otherwise, the screenshot may not represent the component you meant to cover. Locator screenshot assertions are documented in the LocatorAssertions reference.

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

Write an accessible-structure template

Use toMatchAriaSnapshot() when the contract is the accessible structure rather than the exact pixels. The template describes the expected accessibility tree; you can assert on the page or scope the assertion to a locator.

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

test('welcome heading is exposed', async ({ page }) => {
  await page.goto('/');
  await expect(page).toMatchAriaSnapshot(`
    - heading "Welcome"
  `);
});

Replace the illustrative heading with the roles, names, and structure appropriate to your page. Matching is order-sensitive. Leaving out a name or attribute allows a partial match, so include only the detail that forms part of the intended expectation. An overly broad template can miss a change you meant to catch; an unnecessarily detailed one can make unrelated structure changes harder to maintain.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
await expect(page.getByRole('main')).toMatchAriaSnapshot(`
  - heading "Account settings"
  - link "Manage profile"
`);

The official guide also describes using Code Generator or an empty template to generate a snapshot on the fly. Generated output is a starting point, not an accessibility specification: review it against the structure your test should require. Consult the ARIA snapshots guide for template syntax and update workflows.

Snapshot text or another value

For a value that is not an image or an accessibility tree, use a generic snapshot assertion. For example:

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.
import { expect, test } from '@playwright/test';

test('formats a receipt consistently', async () => {
  const receipt = 'Subtotal: $20.00nTax: $1.60nTotal: $21.60';
  expect(receipt).toMatchSnapshot('receipt.txt');
});

Use a descriptive filename and keep the value narrow enough that a diff points to an intelligible change. For visual comparison, prefer toHaveScreenshot() rather than treating image data as a generic value snapshot. See the visual comparisons documentation and snapshot testing documentation for the distinct assertion workflows.

Choose where expected snapshots are stored

Playwright provides snapshotPathTemplate for project-level organization, and screenshot and ARIA assertions have assertion-specific path template settings. A shared template can make a repository’s expected artifacts easier to browse, but the right layout depends on your test-file structure and how you review changes.

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

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

This is an illustrative configuration, not a universally correct path for every repository. The documented template tokens include {testDir}, {testFilePath}, {arg}, {ext}, {platform}, {projectName}, and {snapshotDir}. Confirm the option and token behavior against the API documentation for the Playwright version installed in your project and adapt the path to your repository layout. The TestProject API reference documents snapshotPathTemplate.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Decide between test-adjacent and shared paths

  • Test-adjacent defaults: keep expected artifacts close to the test that owns them when that is how your project already organizes snapshots.
  • Configured shared convention: use a stable, readable path template when you want snapshots collected in a deliberate directory structure.
  • Assertion-specific paths: use screenshot- or ARIA-specific template settings when those artifact types need organization distinct from other snapshots.

Whichever convention you choose, avoid names that obscure which test owns an artifact. If a configured path behaves differently than expected, check the active Playwright version and the resolved test directory, test-file path, and project settings.

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

Keep screenshot baselines stable

Visual comparisons are sensitive to their rendering environment. Playwright documents that output can vary with operating system, browser version, settings, hardware, power source, and headless mode. Generate and compare baselines in the same environment where possible, and treat a browser or operating-system change as a possible source of image differences.

Screenshot assertions wait for two consecutive captures to match before comparison, and animations are disabled by default for screenshot assertions. These measures help reduce unstable captures, but they do not make changing page content deterministic. For dynamic content, use a screenshot stylesheet to hide elements that should not be part of the comparison. To avoid capturing an unwanted hover state, move the pointer away before taking the screenshot. The visual comparisons guide explains these screenshot behaviors.

  • Use stable test data and a consistent test environment for baseline generation and comparison.
  • Exclude timestamps, rotating content, or other intentionally variable regions with an appropriate screenshot stylesheet rather than repeatedly accepting noise.
  • Keep viewport, browser, and project configuration consistent with the environment where the expected result is meant to be checked.
  • Review image diffs for real regressions before updating the expected artifact.

Update snapshots deliberately

When a product change intentionally changes the expected output, run:

npx playwright test --update-snapshots

Do not use an update run as a way to make a failing test green without checking what changed. Review the resulting screenshot, text, or template diff and confirm that the new expectation reflects the intended product behavior. The ARIA snapshot guide describes patch files that can be reviewed and applied, including patch, three-way, and overwrite source-update methods. Use the update workflow supported by your installed version and project setup; the official guide covers ARIA snapshot updates.

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.
Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
  1. Make the product change and run the affected test without updating expectations first.
  2. Inspect the failure and decide whether the observed output is intended.
  3. If the change is intentional, run the update command or the relevant documented patch workflow.
  4. Review the complete artifact diff and commit the new expectation with the code change.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

The first run says it is writing a screenshot

This is expected when a visual reference is absent. Open the generated image, verify that it shows the intended page or locator, and commit it as the baseline. Do not assume that file creation itself proves the rendering is correct.

A screenshot assertion fails on another machine

Different operating systems, browser versions, settings, hardware, power sources, and headless modes can render differently. Reproduce in the baseline environment first; where practical, keep comparison and baseline generation on the same environment. Inspect the diff for environment variation versus a real UI change.

The image diff changes between runs

Look for dynamic page content, animations, or pointer-induced hover states. Playwright’s screenshot assertion already disables animations and waits for two consecutive captures to match; for remaining intentional variability, hide the relevant region with a screenshot stylesheet or move the pointer away before capture.

An ARIA snapshot fails after a seemingly small change

Check both the accessibility tree and the template’s order. ARIA matching is order-sensitive, and names or attributes omitted from the template are partial-match omissions, not assertions that those details have a particular value. Adjust the template only if the changed structure is acceptable for the test’s purpose.

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

A snapshot is saved in an unexpected directory

Review the configured snapshotPathTemplate, assertion-specific path settings, and project/test directory values. Compare the template tokens with the TestProject API reference for your installed Playwright version, then verify the repository-specific path you intended.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

A test cannot find its expected snapshot

Confirm that the expected artifact is present in version control and that the test is running with the same project and path configuration used to create it. If it is genuinely a new expectation, generate it intentionally, inspect it, and commit it rather than silently accepting an unknown artifact.

Or skip the browser setup

If your goal is a clean screenshot file rather than a Playwright regression baseline, ScreenshotNeo returns a screenshot or PDF from one GET request. It is not a replacement for Playwright’s assertion, test runner, or committed snapshot expectations; it is an API option when you need to capture a page without setting up browser automation yourself.

For API options and response details, see the ScreenshotNeo documentation.

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
  • Cookie/consent banners are accepted and removed, along with known newsletter popups and chat widgets, before capture; each step can be turned off.
  • Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month without a card.

Frequently Asked Questions

Should I use a screenshot snapshot or an ARIA snapshot for accessibility testing?

Use an ARIA snapshot when the expected accessible roles, names, and structure are the contract; use a screenshot when you need to compare rendered pixels. They check different things.

Does Playwright create the visual baseline automatically?

If the named expected screenshot is missing, the first run writes it. Inspect the generated image and commit it before relying on later comparisons.

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.