Yes. In a Playwright Test project, set use.screenshot to 'only-on-failure'. Playwright then captures a screenshot after each test failure, including tests that drive an Electron BrowserWindow through Playwright’s Electron integration.
The setting is the right default for CI diagnostics. Use a custom fixture or afterEach hook only when you need conditional logic, a particular filename, or an attachment generated as a buffer for the test report.
Set the built-in failure-only mode
Put the option inside the use object passed to defineConfig in playwright.config.ts:
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
},
});
Playwright Test defines this value as “Capture screenshot after each test failure.” The default is 'off'. The other built-in values are 'on', which captures after every test, and 'on-first-failure', which captures after the first failure of each test.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- KEYBOARD: The keyboard works for Windows with hot keys that enable easy access to Media, My Computer, Mute, Volume up/down, and Calculator
- EASY SETUP: Experience simple installation with the USB wired connection
- VERSATILE COMPATIBILITY: This keyboard is designed to work with multiple Windows versions, including Vista, 7, 8, 10 offering broad compatibility across devices.
- SLEEK DESIGN: The elegant black color of the wired keyboard complements your tech and decor, adding a stylish and cohesive look to any setup without sacrificing function.
- FULL-SIZED CONVENIENCE: The standard QWERTY layout of this keyboard set offers a familiar typing experience, ideal for both professional tasks and personal use.
Keep the property under use; it is a Playwright Test option, not an Electron launch option. Once configured, run the normal test command, for example npx playwright test. A successful test produces no screenshot artifact from this setting. A failed test produces the screenshot through Playwright’s normal test-result and reporter machinery.
Use it with an Electron window
Playwright’s Electron integration exposes an Electron BrowserWindow as a Page-like object. The same screenshot behavior therefore applies when your test obtains its window with firstWindow().
import { test, expect } from '@playwright/test';
import { _electron as electron } from 'playwright';
test('Electron home screen', async () => {
const electronApp = await electron.launch({ args: ['.'] });
const window = await electronApp.firstWindow();
await expect(window).toHaveTitle(/My Electron App/);
await electronApp.close();
});
With screenshot: 'only-on-failure' in the project configuration, a failed assertion in this test causes Playwright to capture the Electron window. You do not need to call window.screenshot() for the built-in mode.
If you want an explicit file instead of relying on the test reporter’s artifact directory, the Electron window supports the normal screenshot path option:
const electronApp = await electron.launch({ args: ['.'] });
const window = await electronApp.firstWindow();
await window.screenshot({ path: 'artifacts/intro.png' });
await electronApp.close();
That explicit call is independent of the failure-only setting. It always runs when execution reaches it, so use it for deliberate snapshots rather than automatic failure diagnostics.
What the three built-in modes mean
| Value | Capture timing | Typical use |
|---|---|---|
'off' |
No automatic screenshots | Default behavior when screenshots are not needed |
'on' |
After every test | Visual records for every test, at the cost of more artifacts |
'on-first-failure' |
After the first failure of each test | Limit repeated failure artifacts while retaining an initial diagnostic image |
'only-on-failure' |
After each test failure | Standard CI diagnostics when successful-test images are noise |
The setting controls when Playwright captures; it does not change whether your Electron application can be launched, whether a window appears, or whether an assertion fails. Those remain separate test concerns.
Rank #2
- Reliable Plug and Play: The USB receiver provides a reliable wireless connection up to 33 ft (1), so you can forget about drop-outs and delays and you can take it wherever you use your computer
- Type in Comfort: The design of this keyboard creates a comfortable typing experience thanks to the low-profile, quiet keys and standard layout with full-size F-keys, number pad, and arrow keys
- Durable and Resilient: This full-size wireless keyboard features a spill-resistant design (2), durable keys and sturdy tilt legs with adjustable height
- Long Battery Life: MK270 combo features a 36-month keyboard and 12-month mouse battery life (3), along with on/off switches allowing you to go months without the hassle of changing batteries
- Easy to Use: This wireless keyboard and mouse combo features 8 multimedia hotkeys for instant access to the Internet, email, play/pause, and volume so you can easily check out your favorite sites
When a manual hook is the better choice
The built-in mode deliberately has low configuration overhead and limited control. Write a fixture or afterEach hook when you need a custom name, a condition that is different from Playwright’s failure definition, or an image buffer that must be attached to a reporter.
Attach a PNG buffer to the test report
Playwright’s TestInfo API accepts a screenshot buffer through testInfo.attach. The attachment is copied to a reporter-accessible location.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →import { test } from '@playwright/test';
test.afterEach(async ({ page }, testInfo) => {
const screenshot = await page.screenshot();
await testInfo.attach('screenshot', {
body: screenshot,
contentType: 'image/png',
});
});
The example attaches on every test because the hook has no condition. To keep the attachment failure-only, add your project’s failure condition around the two statements. A common pattern is to compare the test’s final status with its expected status:
test.afterEach(async ({ page }, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus) {
const screenshot = await page.screenshot();
await testInfo.attach('failure-screenshot', {
body: screenshot,
contentType: 'image/png',
});
}
});
This approach gives you a stable attachment name and lets you add other failure-only artifacts in the same hook. If your project uses a different status policy, keep the condition aligned with that policy rather than blindly copying the example.
Attach a file instead of a buffer
For a direct file, use page.screenshot({ path }). When attaching an existing file, provide a path to testInfo.attach; when attaching an in-memory PNG, provide body and contentType: 'image/png'. Do not provide neither value.
test.afterEach(async ({ page }, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus) {
const path = 'artifacts/electron-failure.png';
await page.screenshot({ path });
await testInfo.attach('electron-failure', {
path,
contentType: 'image/png',
});
}
});
Use a unique path strategy if several workers can execute the hook concurrently. Otherwise, two workers can target the same filename and overwrite one another. The built-in mode avoids that naming work by letting Playwright manage reporter artifacts.
Recommended Free Tools
Rank #3
- All-day Comfort: The design of this standard keyboard creates a comfortable typing experience thanks to the deep-profile keys and full-size standard layout with F-keys and number pad
- Easy to Set-up and Use: Set-up couldn't be easier, you simply plug in this corded keyboard via USB on your desktop or laptop and start using right away without any software installation
- Compatibility: This full-size keyboard is compatible with Windows 7, 8, 10 or later, plus it's a reliable and durable partner for your desk at home, or at work
- Spill-proof: This durable keyboard features a spill-resistant design (1), anti-fade keys and sturdy tilt legs with adjustable height, meaning this keyboard is built to last
- Plastic parts in K120 include 51% certified post-consumer recycled plastic*
Built-in mode or a custom attachment?
| Option | Setup | Capture timing | Control | Best use |
|---|---|---|---|---|
Built-in 'only-on-failure' |
One configuration property | Test failure | Low | Standard CI diagnostics |
Manual screenshot plus testInfo.attach |
Fixture or hook code | Your chosen hook point | High | Custom names, conditions, or extra artifacts |
Start with the built-in property. Move to a hook only when its low control becomes an actual limitation; otherwise you are maintaining code that Playwright already provides.
Electron-specific boundaries
BrowserWindow content is supported
The Electron example uses electronApp.firstWindow() and calls the Page-like screenshot API. This captures the rendered BrowserWindow content that Playwright controls.
Native operating-system dialogs are different
Electron native OS dialogs are outside Playwright’s interception model. A screenshot of the BrowserWindow will not turn a native file picker or permission dialog into page content. Test those dialogs with a strategy appropriate to the operating system or application boundary, and do not expect window.screenshot() to capture them as DOM pixels.
Make sure the window exists before capturing
If firstWindow() cannot obtain a window, the problem occurs before screenshot capture: check the Electron launch arguments, application startup, and the point at which the first BrowserWindow is created. A failure-only setting cannot capture a window that never opened.
CI, artifacts and reliability
Keep the configuration in the test project
Place screenshot: 'only-on-failure' in the configuration used by CI as well as local runs. If CI loads a different config file or project, the setting in another config will not affect that run.
Preserve the reporter output
The automatic screenshot is useful only if the test result directory is retained as a CI artifact. Configure your CI system to upload Playwright’s test-results output after a failed job. If you use testInfo.attach, the attachment is copied to a reporter-accessible location, so retain the corresponding report data too.
Rank #4
- 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
- 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
- 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
- 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
- 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use
Control artifact volume
Failure-only capture avoids screenshot work for passing tests. If a test fails repeatedly in your workflow, inspect how your retry and reporting policy handles each result and retain the artifacts you actually need. Choose unique manual paths when parallel workers can run the same hook.
Check the installed Playwright version
Option names and reporting behavior can evolve. Confirm that the Playwright version installed in the project documents 'only-on-failure' and the testInfo.attach interface before standardizing a configuration across repositories.
Troubleshooting failure screenshots
No screenshot appears after a failed test
- Verify the option is spelled exactly
screenshot: 'only-on-failure'. - Confirm it is nested under
usein the configuration actually loaded by the command. - Check that the test is running under Playwright Test rather than a standalone script; the setting is a Test option.
- Make sure CI retained the Playwright test-results or report directory instead of deleting it during cleanup.
The hook runs, but the report has no image
- For a buffer, pass both
bodyandcontentType: 'image/png'. - For a file, pass
pathand ensure the process can write to that location. - Use the reporter that your CI job actually publishes; an attachment copied to a reporter-accessible location still must be included in the uploaded report.
The screenshot is of the wrong page
Capture the Electron window returned by firstWindow(), or the specific Page object your test is exercising. In a multi-window application, select the intended window rather than assuming the first one is always the relevant surface.
A native dialog is missing
That is expected for an operating-system dialog. Playwright’s screenshot API covers the BrowserWindow surface, not native dialog chrome.
Manual files overwrite each other
Give each worker, test, or retry a distinct path, or prefer testInfo.attach with a buffer and let the reporter manage placement.
Or skip the browser setup
If your requirement is a screenshot of a public web URL rather than an Electron BrowserWindow, ScreenshotNeo provides a single HTTP request. It is not a replacement for testing a local native window, but it removes browser-launch and artifact-plumbing work for web pages. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response reports the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
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 errorsUse the API documentation at https://screenshotneo.com/docs/ for the complete option set. The endpoint supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets or custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage reporting and an OpenAPI specification. Common screenshot-API parameter names are accepted to ease migration.
Best Value
- All-day Comfort: This USB keyboard creates a comfortable and familiar typing experience thanks to the deep-profile keys and standard full-size layout with all F-keys, number pad and arrow keys
- Built to Last: The spill-proof (2) design and durable print characters keep you on track for years to come despite any on-the-job mishaps; it’s a reliable partner for your desk at home, or at work
- Long-lasting Battery Life: A 24-month battery life (4) means you can go for 2 years without the hassle of changing batteries of your wireless full-size keyboard
- Simply plug the USB receiver into a USB port on your desktop, laptop or netbook computer and start using the keyboard right away without any software installation
- Simply Wireless: Forget about drop-outs and delays thanks to a strong, reliable wireless connection with up to 33 ft range (5); K270 is compatible with Windows 7, 8, 10 or later
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}`);
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and yearly billing gives two months free. Sign up for ScreenshotNeo to use the free allowance without adding a card.
Practical decision
For an Electron end-to-end test suite, set use.screenshot to 'only-on-failure' first. It is the supported, lowest-maintenance way to obtain diagnostics after failed tests. Add a conditional hook with testInfo.attach only when naming, status logic, or additional artifact types justify the extra code.
Frequently Asked Questions
Does the setting capture screenshots from a standalone Electron script?
No. screenshot: 'only-on-failure' is a Playwright Test option. A standalone script must call the window’s screenshot method explicitly.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Can I capture an Electron window as a JPEG instead of a PNG?
The documented failure-mode examples and attachment configuration use PNG. Choose an explicit screenshot format only when your installed Playwright version documents that option for the window object.
Will a screenshot show an operating-system file picker?
No. Native OS dialogs are outside Playwright’s interception model; the supported screenshot surface is the Electron BrowserWindow.
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.




