Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use a conditional test.skip(callback, description) inside the test.describe() block. The callback can count matches for the selector, and Playwright will skip every test in that group when the count is zero.
import { test, expect } from '@playwright/test';
const selector = '[data-testid="optional-panel"]';
test.describe('optional panel tests', () => {
test.skip(
async ({ page }) => (await page.locator(selector).count()) === 0,
`Required selector is missing: ${selector}`,
);
test('shows panel content', async ({ page }) => {
await expect(page.locator(selector)).toBeVisible();
});
});
This is the documented group-level pattern. Choose an existence check when the element merely has to be present; choose a visibility check when the tests require it to be visible.
The group-level skip pattern
Declare the tests with test.describe(), then put one conditional test.skip(callback, description) call directly inside that group. The callback receives the Playwright fixtures, including page, so it can inspect the current page before the tests run. Playwright’s API documentation describes this as a way to skip all tests in a file or test.describe() group based on one condition: Test API.
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 glitchesimport { test, expect } from '@playwright/test';
const selector = '[data-testid="optional-panel"]';
test.describe('optional panel tests', () => {
test.skip(
async ({ page }) => (await page.locator(selector).count()) === 0,
`Required selector is missing: ${selector}`,
);
test('shows panel content', async ({ page }) => {
await expect(page.locator(selector)).toBeVisible();
});
test('allows interaction with the panel', async ({ page }) => {
await page.locator(selector).click();
});
});
When count() returns zero, the group is marked skipped and its tests do not continue. When one or more matching elements exist, the callback returns false and the tests run normally. The description is shown with the skip result, making an optional feature’s absence understandable in CI output.
#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
Make sure the page is in the right state first
A zero count is meaningful only after the page has reached the state in which the selector is expected. If your fixture starts at a blank page, redirects through authentication, or renders the panel after navigation, checking too early can skip a group even though the application would eventually create the element.
Navigate before the group condition
Use a project fixture or a setup hook that establishes the required URL and authentication before the callback evaluates the locator. The callback should inspect the same application state that the tests are intended to cover. Do not treat a transient loading state as proof that the feature is unavailable.
Use a stable selector
A test id such as [data-testid="optional-panel"] is generally less sensitive to layout changes than a long CSS path. Keep the selector in one constant so the condition, assertions and skip message cannot drift apart.
Free tools Windows power users keep installed
One-click scans. No signup required.
Existence versus visibility
These checks answer different questions. The locator API documents both matching and visibility operations: Locator API.
Skip when no element exists
Use count() === 0 when the group applies only to pages that render the element at all. This allows a hidden element to satisfy the prerequisite, which is appropriate when later tests are responsible for checking its state.
test.describe('panel tests', () => {
test.skip(
async ({ page }) => (await page.locator(selector).count()) === 0,
`Required selector is missing: ${selector}`,
);
// Tests that require the panel's presence...
});
Skip when the element is not visible
Use isVisible() when the tests require a visible control or panel. A selector can match a node that is hidden with CSS, covered by application state, or otherwise not visible to a user.
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
test.describe('visible panel tests', () => {
test.skip(
async ({ page }) => !(await page.locator(selector).isVisible()),
'The panel is not visible',
);
test('shows panel content', async ({ page }) => {
await expect(page.locator(selector)).toBeVisible();
});
});
Do not substitute a visibility requirement with a count check: that would let hidden markup through. Conversely, do not use visibility when the feature is allowed to exist in the DOM while remaining hidden until a later interaction.
Recommended Free Tools
Group skip versus skipping one test
Scope determines where the skip belongs. A test.skip() call made inside an individual test aborts that test after the call. It does not express a reusable prerequisite for every test in the group.
test('optional panel check', async ({ page }) => {
if ((await page.locator(selector).count()) === 0) {
test.skip();
}
// Only this test is skipped.
});
For a shared condition, place the callback form inside test.describe(). Playwright’s annotations guide covers conditional group skipping: Annotations. The group form prevents repeating the same guard in every test and keeps the reason attached to the group prerequisite.
Writing useful skip descriptions
Always pass a description for a conditional skip. State what was required and, when practical, include the selector or condition. A message such as Required selector is missing: [data-testid="optional-panel"] tells a developer why the tests did not execute without opening the source file.
- Good:
Required selector is missing: [data-testid="optional-panel"] - Good:
The panel is not visible - Weak:
Not applicable - Misleading:
Panel test failedwhen the test was skipped
Common failure modes and fixes
The group skips unexpectedly
Cause: The callback runs before navigation, authentication, or client-side rendering finishes.
Fix: Move navigation and prerequisite setup into the fixture or setup flow that runs before the group condition. Verify the URL and application state at the point where the locator is evaluated.
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.
The group runs but a test fails on visibility
Cause: The existence check found hidden markup.
Fix: Change the callback to !(await page.locator(selector).isVisible()) when visibility is the real prerequisite. Keep the assertion in the test so failures still identify a regression after the group is admitted.
Only one test is skipped
Cause: The skip was called inside that test rather than as a callback in the surrounding test.describe().
Fix: Put one test.skip(callback, description) declaration in the group body. If you need a different condition for a single test, retain the test-local form deliberately.
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 →The selector matches more than one element
Cause: count() checks whether there is at least one match; it does not enforce uniqueness.
Fix: Use a selector that identifies the intended element, or add a separate assertion for the expected count in a test that runs after the prerequisite check.
The callback signature is rejected
Cause: The project may use an older Playwright release whose installed API differs from the current reference.
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
Fix: Check the documentation matching the version installed in your project before relying on the group callback overload. The referenced API material does not establish the release in which this overload was introduced.
Debugging the condition safely
When diagnosing a skip, temporarily log the URL and match count inside the callback, or inspect the page with a headed run. Remove verbose logging after diagnosis so CI output remains readable. A useful diagnostic preserves the same selector used by the test:
test.skip(
async ({ page }) => {
const matches = await page.locator(selector).count();
console.log({ url: page.url(), selector, matches });
return matches === 0;
},
`Required selector is missing: ${selector}`,
);
If the page is expected to render the feature in every environment, a skip may conceal a real defect. In that case, do not guard the group; let the assertion fail and investigate the application or fixture. Conditional skipping is best for genuinely optional capabilities, route-specific UI, and environments where the feature is intentionally absent.
Or skip the browser setup
If your goal is to capture a page rather than run browser assertions, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP or PDF, so you do not need to maintain Playwright navigation code for that capture task. See the ScreenshotNeo documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and whether the request was billed. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
There is a free allowance of 1,000 screenshots per month without a card. Paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Create a free ScreenshotNeo account to try it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Equivalent calls from Python and Node.js
Python
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
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}`);
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()));
The API also supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets, arbitrary viewports, retina scale, PDF paper and margin settings, custom CSS or JavaScript, pre-capture clicks, selector hiding, waits for a selector, delay or network idle, request blocking, custom headers and cookies, user-agent, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Parameter names used by other screenshot APIs are accepted to ease migration.
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.
FAQ
Does a group callback skip the entire file?
No. It governs the surrounding test.describe() group. Use a file-level declaration when the condition should apply to all tests in the file.
Should I use locator.count() or page.$()?
Use the locator-based condition shown here. It keeps the prerequisite aligned with Playwright’s locator API and the selector used by the assertions.
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 & 11Can a skipped group hide a regression?
Yes. If the selector is mandatory in every supported environment, a skip is the wrong policy; allow the test to fail so the missing element is reported as a defect.
Frequently Asked Questions
Can I add multiple prerequisites to one group?
Yes. Combine them in the callback and return true when any required condition is absent, then describe the combined reason clearly.
Does isVisible() wait for an element to appear?
The condition expresses a visibility check at callback evaluation time. Arrange navigation and rendering prerequisites before it, rather than treating the callback as a replacement for page setup.
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

