Use page.screenshot() for an image at an exact point in a test, and configure Playwright Test’s use options when every test (or only failures and retries) should produce artifacts. Record videos with video in the test runner or recordVideo on a manually created browser context; close the context before reading or relying on the video file.
Choose the capture method first
| Goal | Recommended approach | Where it is configured |
|---|---|---|
| One diagnostic image at a known step | await page.screenshot({ path: 'screenshot.png' }) |
Inside the test |
| Images for every test | screenshot: 'on' |
Playwright Test use configuration |
| Images only when debugging failures | screenshot: 'only-on-failure' or 'on-first-failure' |
Playwright Test use configuration |
| Videos for selected runs | video: 'on', 'retain-on-failure' or a retry mode |
Playwright Test use configuration |
| Recording outside Playwright Test | recordVideo: { dir: 'videos/' } |
browser.newContext() |
| Visual regression | await expect(page).toHaveScreenshot() |
Test assertion and snapshot directory |
Screenshots, videos and traces are disabled by default in Playwright Test. The current option names and modes are documented in the use-options guide and the TestOptions API.
Capture a screenshot at an exact point
After navigating and performing the action you want to inspect, call page.screenshot(). The call captures the page in its current state, so put it after the state change you care about.
import { test } from '@playwright/test';
test('checkout confirmation', async ({ page }) => {
await page.goto('https://example.com/checkout');
await page.getByRole('button', { name: 'Place order' }).click();
await page.getByRole('heading', { name: 'Order confirmed' }).waitFor();
await page.screenshot({ path: 'artifacts/confirmation.png', fullPage: true });
});
path determines the output filename. fullPage: true extends the capture beyond the visible viewport; omit it for the viewport currently on screen. For test-specific output, use Playwright Test’s testInfo.outputPath() so parallel workers do not overwrite one another.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- 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.
import { test } from '@playwright/test';
test('unique artifact path', async ({ page }, testInfo) => {
await page.goto('https://example.com');
const file = testInfo.outputPath('state.png');
await page.screenshot({ path: file, fullPage: true });
});
The file is normally placed under the test runner’s output area, commonly test-results, with a worker- and test-specific path.
Configure automatic screenshots in Playwright Test
Put a use block in playwright.config.ts. Automatic capture is useful when you want consistent evidence without adding a screenshot call to every test.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
video: 'on-first-retry'
}
});
Screenshot modes
'on'creates a screenshot for every test run.'only-on-failure'captures failed tests.'on-first-failure'captures on the first failure according to the TestOptions API.'off'disables automatic screenshots (the default).
Choose 'on' for a complete visual trail, but expect more files and storage. Failure-only modes reduce artifact volume while preserving evidence when a test breaks. A direct page.screenshot() call still runs regardless of the automatic setting.
Video modes
Set video to control which runs are recorded and retained. Supported choices include 'on', 'retain-on-failure', 'on-first-retry', 'on-all-retries', 'retain-on-first-failure' and 'retain-on-failure-and-retries'. The distinction matters: some modes record every run but keep only selected recordings, while others record only retries or failures. The official video guide describes the lifecycle and current behavior.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #2
- 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 { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'on',
video: 'retain-on-failure'
}
});
Video artifacts generally appear in the test output directory, typically test-results. Your reporter and project settings can affect the exact folder and filename.
Record video with a manually created browser context
If you are using Playwright Library rather than Playwright Test, enable recording when creating the context.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const context = await browser.newContext({
recordVideo: { dir: 'videos/' },
viewport: { width: 1280, height: 720 }
});
const page = await context.newPage();
await page.goto('https://example.com');
await page.getByRole('link', { name: 'More information' }).click();
await context.close(); // finalizes the recording
await browser.close();
Do not expect the final video path before the page or context closes. If you need the path after closing, retain the page object and call its video API after closure:
const video = page.video();
await context.close();
console.log(await video?.path());
The exact encoding and path are managed by Playwright. Keep the recording directory writable in local runs and CI.
Rank #3
- 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.
Control video size and annotations
Set an explicit viewport when predictable dimensions matter. When no viewport is explicitly set, the documented default video size is 800×450. Otherwise Playwright scales the viewport to fit within 800×800. The video guide also supports visual action annotations and an overlay containing test information; annotation duration defaults to 500 milliseconds. These defaults and APIs can change between Playwright releases, so check the current video documentation when upgrading.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
viewport: { width: 1440, height: 900 },
video: 'on-first-retry'
}
});
A fixed viewport makes comparisons and review easier, while a smaller viewport can reduce video size and runtime overhead. Decide based on whether the recording is a complete history or only failure evidence.
Use screenshots as visual-regression baselines
toHaveScreenshot() turns a screenshot into an assertion rather than a debugging artifact.
import { test, expect } from '@playwright/test';
test('landing page visual contract', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot('landing.png');
});
On the first execution, Playwright creates the reference image. Later executions compare the current rendering with that baseline and fail when they differ. PNG is the default snapshot format; use a filename ending in .webp when you want WebP instead.
Rank #4
- 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
Keep the comparison environment stable
Rendering can vary with the host operating system, browser version, browser settings, hardware, power source and headless mode. Generate and compare baselines in the same environment whenever possible. Pin browser versions in CI, use a fixed viewport, wait for application data and fonts to settle, and avoid updating baselines from a different machine without reviewing the diff. See the visual comparisons guide for the documented constraints.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Make captures reliable
Wait for the state you intend to record
Prefer locator assertions and explicit readiness checks over arbitrary sleeps. For a screenshot after a network-driven component appears, wait for its locator or a testable state before calling the capture. A screenshot taken during an animation or before fonts load can become a misleading baseline.
Prevent artifact collisions
Parallel workers can run the same test simultaneously. Use testInfo.outputPath(), unique test names or separate project output folders rather than a shared filename such as latest.png.
Manage storage
Recording every run produces substantially more data than failure-only modes. Retain videos and full-page images only for the period your debugging or review process needs, and upload artifacts from CI intentionally. A screenshot mode and a video mode can be selected independently.
Best Value
- 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.
Protect sensitive content
Screenshots and videos include everything visible in the browser: account names, order data, tokens rendered into pages and personal information. Use test accounts, hide sensitive selectors before capture, and restrict artifact permissions in CI.
Troubleshoot common failures
No screenshot appears
- Automatic capture is off: set
screenshotunderuse, or add an explicitpage.screenshot()call. - The test passed: failure-only modes intentionally keep no image for a passing run.
- The path is wrong: inspect the reporter’s output directory, commonly
test-results, and print the value returned bytestInfo.outputPath(). - The process cannot write: choose a writable directory and create required parent directories in your test setup.
Video file is missing or empty
- Context still open: call
await context.close(); recording is finalized on close. - Mode retained nothing: a retain-on-failure or retry mode may discard a successful first run by design.
- Wrong context: recording must be enabled on the context that owns the page.
Visual assertion fails on an unchanged page
- Confirm the same browser version, operating system, viewport and headless setting used to create the baseline.
- Wait for fonts, images, animations and asynchronous data before the assertion.
- Review the diff before updating the baseline; an environment change is not automatically an application change.
Full-page image is unexpectedly long or clipped
Full-page capture includes the document’s rendered height, which can expose lazy content and sticky elements repeatedly. Compare it with a viewport screenshot, and capture a specific element when only one component matters.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. It removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and each response identifies the page verdict and billing status in headers. Its MCP tools—take_screenshot, get_page_info and capture_pdf—let Claude, Cursor and other MCP clients capture pages without you wiring a browser. Free usage includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
For a one-call image, see the ScreenshotNeo API documentation:
Free tools Windows power users keep installed
One-click scans. No signup required.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Sign up for 1,000 free screenshots a month with no card.
When each approach fits
- Direct screenshot: best for a single checkpoint, a bug report or a deliberately named artifact.
- Automatic screenshot: best when every test or every failure needs consistent evidence.
- Automatic video: best for replaying interactions, especially failed retries; choose retention modes to control storage.
- Manual context recording: best for standalone scripts, crawlers or workflows that do not use Playwright Test.
- Visual assertion: best when a rendering change should fail the test and be reviewed as a diff.
Frequently Asked Questions
Can I take both a screenshot and a video in one Playwright test?
Yes. Configure the desired screenshot and video modes under the same use block, or call page.screenshot() while the context has video recording enabled.
Where should I store screenshots in parallel CI jobs?
Use testInfo.outputPath() or another worker-specific path, then publish the test output directory as a CI artifact.
Is a Playwright video available before the test ends?
The finalized recording is available only after its page or browser context closes.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesQuick 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.

