Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the test fail with a text assertion, not with the screenshot alone. In Playwright Test, assert the required copy with toHaveText or toContainText, then use toHaveScreenshot() if the rendered pixels also need to match an approved baseline.

Use a text assertion before the screenshot assertion

Text and pixels answer different questions. A locator assertion tells you directly that required content is absent or changed. A screenshot assertion tells you that the rendered image differs from a stored reference, but its failure can be caused by layout, fonts, animation, or other visual changes.

import { test, expect } from '@playwright/test';

test('page contains the expected copy and matches its visual baseline', async ({ page }) => {
  await page.goto('/page-under-test');

  await expect(page.getByRole('heading', { name: 'Account overview' })).toBeVisible();
  await expect(page.locator('main')).toContainText('Your balance');
  await expect(page).toHaveScreenshot();
});

If Your balance is missing, the toContainText assertion fails with a content-focused message. If the text is present but the page looks different from the approved image, toHaveScreenshot reports a visual mismatch.

The example uses semantic locators and scopes the copy check to main. Avoid asserting an ambiguous page-wide substring when the same words can occur in navigation, a footer, or hidden content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

Choose the assertion that matches the requirement

Require an exact string with toHaveText

Use toHaveText('Expected exact text') when the locator’s text must match exactly. Nested elements contribute to the locator’s text content, so inline markup does not prevent the assertion from working. A regular expression is also accepted when a controlled variation is valid.

await expect(page.getByRole('heading', { name: 'Account overview' }))
  .toHaveText('Account overview');

await expect(page.locator('[data-testid="status"]'))
  .toHaveText(/Signed in as .+@example.com/);

Require a phrase with toContainText

Use toContainText('Expected phrase') when the locator may contain additional copy, such as a card, table, or main region.

await expect(page.locator('[data-testid="balance-card"]'))
  .toContainText('Your balance');

Both methods consider text in descendant elements and support regular expressions. Select the smallest meaningful region so the assertion describes the behavior you actually care about. See the Playwright LocatorAssertions API for the exact matching behavior.

Why the assertion must be asynchronous

Playwright web-first assertions are asynchronous and retry while the page settles. They re-fetch the locator and check it repeatedly until it passes or the assertion timeout is reached; Playwright documents a five-second default assertion timeout. Always use await.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.
// Correct: waits for asynchronously rendered content.
await expect(page.locator('main')).toContainText('Your balance');

// Avoid a one-time read that can race the application.
const text = await page.locator('main').textContent();
expect(text).toContain('Your balance');

The second form captures one instant. If data arrives shortly afterward, it can fail even though the UI would become correct moments later. Use the retrying assertion for content that is loaded by a request, hydration, or client-side state update. Details on retry behavior and timeout configuration are in Playwright’s assertions documentation.

Build a reliable visual screenshot check

Generate and review the first baseline

  1. Navigate to the page and establish the application state needed by the test.
  2. Run the test with toHaveScreenshot() for the first time. Playwright creates an expected image for that project and snapshot name.
  3. Open the generated image and verify that it represents the intended UI, including the required text.
  4. Commit the reviewed baseline with the test. Future runs compare their output with that file.

Do not accept a baseline automatically just because the test produced one. A baseline containing missing copy makes every later run “pass” against the wrong expectation. The visual comparisons guide describes baseline creation and review.

Choose page or component scope

await expect(page).toHaveScreenshot() compares the whole page. Use a locator when the requirement concerns one component and unrelated page changes should not fail the test:

const summary = page.getByRole('region', { name: 'Account summary' });
await expect(summary).toContainText('Your balance');
await expect(summary).toHaveScreenshot();

Keep the text assertion on the same region that the visual assertion represents when the component itself is the acceptance boundary.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Keep rendering conditions consistent

Playwright warns that screenshots can vary with the operating system, browser version, fonts, browser settings, hardware, power source, and headless mode. Generate and compare baselines in a consistent browser and host environment. A changed font or browser build can create a pixel diff even when the application code is unchanged.

For intentionally volatile areas, use screenshot options that disable animations or apply a stylesheet, or hide a region that is outside the behavior under test. Never hide the text or visual state that this test is meant to verify. Stabilize the data and clock in your test setup rather than masking the acceptance condition.

A complete test for missing, exact, and dynamic copy

This example checks a heading exactly, checks a phrase inside the main content, and then compares the final page image:

import { test, expect } from '@playwright/test';

test('account overview has required copy and visual layout', async ({ page }) => {
  await page.goto('/account');

  const main = page.locator('main');
  await expect(page.getByRole('heading', { name: 'Account overview' }))
    .toBeVisible();
  await expect(main).toContainText('Your balance');
  await expect(main).toContainText(/Last updated:s+d{4}-d{2}-d{2}/);
  await expect(page).toHaveScreenshot();
});

If the wording must not include a date or other variable suffix, replace the regular expression with toHaveText and the complete expected string. If the copy is allowed to vary in a controlled way, keep the expression narrow; a broad pattern can let an incorrect message pass.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

Diagnose failures in the right order

Symptom Likely cause Fix
Text assertion times out The locator is wrong, the copy is not rendered, or the application state was not established. Inspect the locator in the trace or DOM, narrow it to the intended region, and perform the required navigation, login, or data setup before asserting.
Exact-text assertion fails but the words are visible Whitespace, punctuation, nested text, or additional content makes the locator’s text different from the expected string. Use toContainText for an allowed surrounding context, or update the exact expected value to match the deliberate UI copy.
Screenshot fails while text passes Layout, fonts, color, spacing, animation, or another pixel-level change differs from the baseline. Open the diff, decide whether the change is intentional, and review or regenerate the baseline only after confirming the UI is correct.
Screenshot is flaky between machines Browser, operating system, font, hardware, power mode, or headless rendering differs. Pin the browser and run comparisons in the same environment used to create the baseline.
Only the first run behaves differently The first run creates a reference image rather than comparing with an existing one. Review that generated image and commit it only when it shows the intended state.
Dynamic banner causes repeated diffs A changing animation, timestamp, ad, or server response is outside the stable UI contract. Control the data or timing, disable the animation, or apply a targeted stylesheet. Do not mask the required text.

Important Playwright limitation

Screenshot assertions are part of the Playwright Test runner. The official PageAssertions documentation states that screenshot assertions only work with the Playwright test runner; they are not a generic assertion available from every way of driving a browser. If your project uses another runner or only the lower-level browser library, keep the semantic text check in that framework or move the visual check into Playwright Test. See PageAssertions for the supported behavior and options.

When a screenshot is evidence, not the test

Use the two assertions together when both content and appearance matter. For a content-only acceptance test, the text assertion is clearer and less sensitive to rendering differences. For a visual-regression test, the screenshot is valuable after the required text has passed. This separation makes failures actionable: missing copy points to application content, while a pixel diff points to presentation or environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need an image of a URL rather than a Playwright baseline test, ScreenshotNeo is a website screenshot API and MCP server. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

One GET request returns PNG, JPEG, WebP, or PDF output. The API accepts the capture controls you need for test fixtures, including full-page lazy-image loading, CSS-selector element capture, device and viewport settings, dark mode, retina scale, custom CSS and JavaScript, clicks, waits, hidden selectors, request and resource blocking, headers, cookies, user agent, authorization, timezone, geolocation, transparent backgrounds, resizing, a chosen cache TTL, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

cURL

curl -G 'https://api.screenshotneo.com/v1/shot' -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for parameters and response details.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.

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}`);

Every feature is available on every plan. The Free plan includes 1,000 shots per month without a card; Starter is $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000. Yearly billing gives two months free.

Plan Monthly shots Price
Free 1,000 $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can a screenshot diff prove that text is accessible to users?

No. A screenshot checks pixels. Keep a semantic locator assertion for the required wording and accessible name, then use the screenshot for visual appearance.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I update a baseline whenever a screenshot test fails?

No. Inspect the generated image and diff first. Update the baseline only when the changed UI is intentional and the required text and state are correct.

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.