Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsFor Playwright Test, enable the built-in failure artifact with use.screenshot: 'only-on-failure' in playwright.config.ts. Playwright then captures a screenshot after a test fails, without custom error-handling code. Screenshots are off by default and are written with the test’s other artifacts to the configured output directory, normally test-results. Use page.screenshot() with testInfo.attach() when you need a screenshot at a specific point, and enable first-retry tracing when a CI failure needs more context than one image can provide.
1. Turn on automatic screenshots for failed tests
The shortest solution is a single Playwright Test option:
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
},
});
Run your tests normally:
npx playwright test
When a test fails, Playwright captures a screenshot after the failure and exposes it through the test reporter. The option is documented in Playwright’s configuration guide and the TestOptions API.
What the setting captures
'only-on-failure'captures after each failed test.'on-first-failure'captures only the first failure for a test that is retried.'on'captures every test, including passing tests.'off'disables screenshots and is the default.
Unless you request otherwise, the image is a viewport screenshot rather than a full-page image. Playwright also supports screenshot options such as fullPage and omitBackground; configure those when your failure artifact needs the entire document or transparency.
#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.
Example with a project and output directory
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
outputDir: 'test-results',
use: {
screenshot: 'only-on-failure',
},
});
Keep the output directory in CI artifacts so the image remains available after the runner is deleted. The exact display depends on your reporter, but Playwright copies screenshots and other attachments into locations reporters can expose.
2. Choose the right screenshot mode for retries
The automatic mode is applied to test outcomes, not to a JavaScript try/catch block. If a test assertion throws, Playwright records the failure and performs the configured capture. This is generally safer than placing a screenshot after an assertion, because code after a thrown assertion is never reached.
| Need | Configuration | What you get |
|---|---|---|
| A screenshot for every failed test | screenshot: 'only-on-failure' |
One failure artifact per failed test execution. |
| A screenshot only on the first failed attempt | screenshot: 'on-first-failure' |
Less duplicate output when retries are enabled. |
| A screenshot for all outcomes | screenshot: 'on' |
Passing and failing screenshots; more storage and processing. |
| No screenshots | screenshot: 'off' |
No automatic image artifact. |
Use only-on-failure when the goal is ordinary failure diagnosis. Select on-first-failure if retries are part of your CI policy and you want the first broken state rather than a second image of the retry.
3. Capture and attach an image at an exact point
Automatic capture happens at the end of a failed test. For a checkpoint—such as immediately before submitting a form—capture manually and attach the returned buffer to the test result:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan 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 { test, expect } from '@playwright/test';
test('shows the expected result', async ({ page }, testInfo) => {
await page.goto('https://playwright.dev');
const screenshot = await page.screenshot();
await testInfo.attach('screenshot', {
body: screenshot,
contentType: 'image/png',
});
await expect(page).toHaveTitle(/Playwright/);
});
page.screenshot() returns a Buffer by default. testInfo.attach() makes that buffer a named, reporter-accessible attachment. The TestInfo API is available in test functions, hooks, and test-scoped fixtures.
Save a file and attach its path
import path from 'node:path';
import { test } from '@playwright/test';
test('records a checkout checkpoint', async ({ page }, testInfo) => {
await page.goto('https://example.com/checkout');
const file = testInfo.outputPath('checkout-before-submit.png');
await page.screenshot({ path: file, fullPage: true });
await testInfo.attach('checkout-before-submit', {
path: file,
contentType: 'image/png',
});
});
testInfo.outputPath() keeps the file inside the test’s isolated output folder, avoiding collisions when workers run in parallel. Use either a buffer or a path; attaching is what makes the image part of the test report.
Full-page and transparent captures
const image = await page.screenshot({
fullPage: true,
omitBackground: true,
});
await testInfo.attach('full-page-transparent', {
body: image,
contentType: 'image/png',
});
Full-page mode can be substantially taller than the viewport and may include content revealed while the page is laid out. Use it for document-layout failures; use the default viewport image when the visible interaction state is more useful.
4. Why a manual screenshot can be missing
- The assertion ran first: an exception stops execution before the screenshot line. Put the checkpoint before the assertion, or use automatic failure capture.
- The page was already closed: a fixture teardown or explicit
page.close()leaves no page to capture. Capture before teardown. - The attachment is not in the report: calling
page.screenshot()alone returns or saves an image but does not attach it. CalltestInfo.attach()or configure the screenshot mode. - The wrong output folder was archived: preserve the configured
outputDir(commonlytest-results) as a CI artifact. - Parallel tests overwrite a filename: use
testInfo.outputPath()or unique names instead of a shared path.
5. Add tracing for CI failures
A screenshot shows one rendered state. A trace shows the actions and surrounding state that led there. Playwright’s Best Practices recommends Trace Viewer for CI failures and advises tracing on the first retry rather than recording every test.
Recommended Free Tools
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.
import { defineConfig } from '@playwright/test';
export default defineConfig({
retries: 1,
use: {
screenshot: 'only-on-failure',
trace: 'on-first-retry',
},
});
With one retry configured, a failed first attempt produces a trace for the retry. Open it with:
npx playwright show-trace path/to/trace.zip
For a local diagnostic run, Playwright also supports:
npx playwright test --trace on
The Trace Viewer presents a timeline with actions, DOM snapshots, network requests, metadata, and attachments. When screenshots are enabled, it can show a screenshot filmstrip alongside those events. Tracing every test creates more data and is described by Playwright as performance-heavy, so reserve it for retries or targeted debugging.
Do not confuse Test tracing with the low-level tracing API
browserContext.tracing records browser operations and network activity, but it does not record Playwright Test assertions. For complete test failure traces, configure the Playwright Test trace option as shown above. The distinction is covered in the Tracing API reference.
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
6. A practical configuration for local runs and CI
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
outputDir: 'test-results',
retries: process.env.CI ? 1 : 0,
reporter: process.env.CI ? [['list'], ['html']] : 'list',
use: {
screenshot: 'only-on-failure',
trace: 'on-first-retry',
},
});
This keeps local runs lightweight while adding a retry trace in CI. After a local failure, inspect the HTML report with npx playwright show-report if you selected the HTML reporter. In a CI system, upload test-results and the HTML report as job artifacts before the job cleans its workspace.
7. Troubleshooting common errors
“I enabled screenshots but no image appears”
Confirm the test actually failed, the configuration file is the one loaded by the command, and the reporter or CI job is retaining test-results. Screenshots are disabled by default; a project-level use block can also override a higher-level setting.
“The image is only the visible viewport”
That is the default behavior. Use fullPage: true for a manual capture, or set the relevant screenshot options in the project configuration supported by your installed Playwright version.
“The screenshot is blank or shows a loading page”
The image reflects the page state at capture time. Wait for a stable locator or URL before a manual checkpoint, for example await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible(). For an end-of-test failure, investigate the preceding timeout or navigation error rather than masking it with an extra delay.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Best 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.
“Retries produced too many artifacts”
Change only-on-failure to on-first-failure, or keep screenshots on every failure and archive only the report you need. Pairing first-retry tracing with first-failure screenshots limits duplication while preserving context.
“The trace is huge”
Do not enable tracing globally for every test unless you accept the storage and runtime overhead. on-first-retry records the diagnostic run most likely to explain a CI-only failure.
8. Performance, reliability, and retention choices
- Capture only failures by default: it avoids image work for passing tests and keeps reports readable.
- Use full-page selectively: long pages produce larger files and are harder to scan than a viewport image.
- Prefer isolated output paths: Playwright workers can run concurrently, so per-test paths prevent races.
- Retain artifacts deliberately: configure CI retention to match the time your team investigates failures; do not assume a hosted runner keeps files after the job.
- Use traces for context, images for quick visual evidence: a trace can explain timing, DOM, and network state that a screenshot cannot.
Or skip the browser setup
If you need a rendered image of a URL rather than a Playwright test artifact, ScreenshotNeo provides a single-request screenshot API. It accepts consent banners before capture, removes more than 60 known consent platforms along with newsletter popups and chat widgets, and lets each cleanup step be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; each response identifies the result with X-Page-Verdict and X-Billed headers.
Using the ScreenshotNeo API documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://playwright.dev -o shot.webp
The same request in Python:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://playwright.dev"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
And in Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://playwright.dev' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Its 63 options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDFs, custom CSS and JavaScript, click-before-capture, waits, request blocking, headers and cookies, user-agent and authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-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. Common parameter names used by other screenshot APIs also work.
| Plan | Included screenshots | Price |
|---|---|---|
| Free | 1,000 per month | No card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing gives two months free, and every feature is available on every plan. Start with 1,000 free screenshots a month with no card.
9. Which approach should you use?
| Situation | Best choice | Reason |
|---|---|---|
| Every failed Playwright test needs a visual artifact | use.screenshot: 'only-on-failure' |
Minimal configuration and no custom error path. |
| You need a named image at a checkpoint | page.screenshot() plus testInfo.attach() |
Exact timing and reporter-visible naming. |
| A CI failure needs actions, DOM, and network context | trace: 'on-first-retry' |
Trace Viewer adds context around the image. |
| You need screenshots of arbitrary URLs outside a test run | ScreenshotNeo | Clean captures, only clean shots billed, MCP access, and a $5 paid plan. |
10. Final implementation checklist
- Add
screenshot: 'only-on-failure'to the active Playwright Test configuration. - Choose
on-first-failurewhen retries make duplicate images unhelpful. - Use
testInfo.attach()for checkpoints that must appear in reports. - Use
testInfo.outputPath()for files created by parallel tests. - Enable
trace: 'on-first-retry'for CI diagnosis and retain the trace archive. - Use
fullPageonly when a viewport image cannot answer the debugging question. - Verify that your CI system archives
test-resultsand any HTML report.
Frequently Asked Questions
Can I capture a screenshot from a Playwright fixture?
Yes. Test-scoped fixtures receive TestInfo, so they can call page.screenshot() and testInfo.attach() just like a test or hook.
Does a failure screenshot prove why the test failed?
No. It records the rendered state after failure. Assertions, logs, and a first-retry trace may be needed to establish the cause.
Can I use the low-level tracing API instead of Playwright Test tracing?
You can, but browserContext.tracing does not record test assertions. Playwright Test’s trace option is the more complete choice for test failures.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.

