Use Playwright Test’s expect(page).toHaveScreenshot() when you want a test to compare a page or element with a reviewed visual baseline. Use page.screenshot() when you need an image file as debugging evidence, and configure automatic screenshots when you want Playwright to save them after failures. These approaches serve different purposes: a saved screenshot is an artifact, while a screenshot assertion can fail the test when the rendered result changes.
Choose the right kind of screenshot
Before adding screenshot code, decide what the image needs to do. A file for investigating a failed test does not need a baseline; a visual regression check does.
| Goal | Use | What happens |
|---|---|---|
| Save an image for debugging, documentation, or later inspection | page.screenshot() or a locator’s screenshot() |
Playwright writes an image. Saving it alone does not compare it with an expected image or fail the test because pixels changed. |
| Fail a test when a page or element differs visually | expect(page).toHaveScreenshot() or a locator’s toHaveScreenshot() |
Playwright creates or compares a reference image and reports visual differences. |
| Keep images automatically when tests fail | use.screenshot: 'only-on-failure' or 'on-first-failure' |
Playwright captures debugging evidence according to the configured failure mode; it does not establish a visual baseline. |
The examples below use Playwright Test and its @playwright/test package. The screenshot assertion belongs to the Playwright test runner; calling a page or locator screenshot method does not, by itself, perform that assertion. See the Page API, Locator API, PageAssertions API, and LocatorAssertions API.
Save a screenshot from a Playwright test
Call page.screenshot() after navigating to the state you want to inspect. Set path to choose the output file. The default capture is the current viewport; request a full-page image explicitly when you need the whole scrollable page.
Recommended Free Tools
#1 Best Overall
- 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
Capture the viewport or full page
import { test } from '@playwright/test';
test('save a page screenshot', async ({ page }) => {
await page.goto('/');
await page.screenshot({ path: 'artifacts/page.png' });
});
test('save a full-page screenshot', async ({ page }) => {
await page.goto('/');
await page.screenshot({ path: 'artifacts/full-page.png', fullPage: true });
});
Use a locator when only a specific component matters. This keeps the image focused and can make an artifact easier to review than a full-page capture.
test('save the main content', async ({ page }) => {
await page.goto('/');
await page.getByRole('main').screenshot({ path: 'artifacts/main.png' });
});
Playwright’s page and locator screenshot APIs document options for such tasks as full-page capture, masking, and animation handling. Check the relevant API when you need to control those details: page.screenshot() and locator.screenshot().
Add a visual regression assertion
For a visual check, take the screenshot through Playwright Test’s expect API. Start with a stable, representative state; then assert on the whole page or a locator.
Rank #2
- 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
import { test, expect } from '@playwright/test';
test('landing page matches its visual baseline', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot('landing.png');
});
test('main content matches its visual baseline', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('main')).toHaveScreenshot('main.png');
});
Screenshot assertions wait for consecutive captures to stabilize before comparing the result. On the first run, the expected image does not exist, so Playwright writes a reference screenshot. Later runs compare against it. That first generated image is a proposal for a baseline, not proof that the page is correct: open and review it before committing it. The official visual comparisons guide explains the workflow and available options.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →PNG is the default snapshot format. The guide also documents WebP snapshots when the name ends in .webp; both formats are described there as lossless. You can provide an explicit name, such as 'landing.png', or omit it to let Playwright generate a name. For the assertion details, see PageAssertions and LocatorAssertions.
Create, review, and update baselines
Keep expected screenshots with the test code so changes can be reviewed alongside the tests. After an intentional UI change, regenerate them with:
Rank #3
- 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.
npx playwright test --update-snapshots
Review the image differences before accepting the update. A blanket baseline refresh can hide an unintended layout or styling regression just as easily as it can record an intentional redesign. The visual comparison guide recommends committing the snapshot directory and reviewing changes in it.
Playwright names snapshots in relation to the test and project/browser context. In multi-project configurations, the project name may appear in place of a browser or platform name. If the default layout does not suit your repository, the snapshot location can be customized with snapshotPathTemplate; see the TestConfig API and TestProject API.
Make visual checks repeatable
Screenshot comparisons are sensitive to the rendering environment. Playwright’s guide identifies the host operating system, browser version, settings, hardware, power source, and headless mode as factors that can affect output. Generate and compare baselines in the same environment wherever practical. If a team deliberately tests several browser or platform projects, expect to maintain context-appropriate snapshots rather than assume every environment renders identically.
Rank #4
- 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
Control application state and dynamic content
Before capturing, get the page into a predictable state: wait for the relevant UI to appear, use deterministic test data, and avoid capturing while the application is still changing. For content that must remain in the page but changes between runs, Playwright supports masking elements; it also supports applying a stylesheet to filter volatile content. Animation controls can disable or otherwise manage animations. These techniques reduce sources of variation, but do not guarantee that every nondeterministic source has been eliminated. Refer to the visual comparisons guide and Page API for the applicable options.
Set a difference tolerance deliberately
Screenshot assertions accept comparison options such as maxDiffPixels, and screenshot assertion behavior can also be configured globally or per project. A tolerance can be useful when the team has decided which small differences are acceptable. It is not a correction for unstable rendering: choose it intentionally and inspect reported diffs instead of raising it until the test passes. See the visual comparison guide and TestConfig API.
Capture screenshots automatically when tests fail
If the purpose is diagnostic evidence rather than visual comparison, configure the test’s screenshot mode. For example, this saves screenshots only for failed tests:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
- 【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.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
},
});
The documented modes are 'off', 'on', 'only-on-failure', and 'on-first-failure'; the option defaults to 'off'. Playwright places screenshots and other test outputs in the test output directory, typically test-results. Choose 'on-first-failure' when you want evidence for the first failure without collecting it for every retry. Consult Configuration (use) and the TestOptions API for configuration details.
Or skip the browser setup
For a standalone screenshot of a public URL—not a Playwright baseline assertion—ScreenshotNeo provides a screenshot API. One GET request can return an image or PDF. This is a separate capture path: it does not create or update Playwright’s expected snapshot files.
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}`);
See the ScreenshotNeo API documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.
Troubleshoot common screenshot-test problems
- The first visual test reports a missing snapshot. This is the baseline-creation step. Inspect the generated image and commit it only if it shows the intended state.
- The assertion fails after an expected design change. Review the actual diff, then run
npx playwright test --update-snapshotsand inspect the updated files before committing. - The screenshot differs between local and CI runs. Compare the browser, operating system, headless mode, settings, and other rendering conditions. Keep baseline generation and comparison in the same environment when practical.
- The page screenshot includes content below the fold—or omits it. The default is a viewport screenshot. Set
fullPage: truewithpage.screenshot()when the whole scrollable page is required. - A screenshot is saved, but the test does not fail on a visual change. A call to
screenshot()saves an artifact; replace or supplement it withexpect(page).toHaveScreenshot()for a baseline comparison. - Visual assertions are flaky around changing content. Stabilize the application state first, then consider masking volatile elements, suppressing them with a stylesheet, or managing animations. Those controls reduce variation but are not a substitute for deterministic test setup.
- The mismatch threshold is hiding useful changes. Revisit the configured tolerance, including
maxDiffPixels, and inspect the image diff. A larger allowance can permit more visual change; it does not make rendering more stable. - Automatic failure screenshots are missing. Check that the active Playwright configuration sets
use.screenshotto a failure mode rather than its default'off', and look in the test output directory, typicallytest-results.
Choose a strategy for multi-project visual testing
When a suite covers multiple browsers or platforms, make these decisions explicitly:
Free tools Windows power users keep installed
One-click scans. No signup required.
- Scope: assert on the whole page or a locator, based on what the test is meant to protect.
- Purpose: use saved artifacts for debugging and assertions for visual regression detection.
- Environment: decide whether one canonical rendering environment is sufficient or whether each project needs its own reviewed baseline.
- Repeatability: control state and decide which dynamic content, animations, or elements should be masked or suppressed.
- Change approval: review snapshot updates and set any pixel-difference tolerance with a clear understanding of what differences it permits.
These choices follow from Playwright’s page and locator capture APIs, project-aware snapshots, environment-dependent rendering, and configurable comparison options. A screenshot test is most useful when its baseline represents an intentional state and changes to that baseline remain visible in code review.
Frequently Asked Questions
Where does Playwright put automatic failure screenshots?
They are written with the test outputs, typically under test-results; the exact output directory can depend on the project configuration.
Can a Playwright screenshot snapshot use WebP?
Yes. The visual comparison guide documents WebP snapshots when the snapshot name ends in .webp; PNG is the default.
Quick Recap
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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors

