Guide6 min read

Playwright Assertions: What They Let Slip Through on the Screen

Playwright assertions check the DOM, not the render. Three green tests that hide a defect, and how to compare renders without rewriting tests.

Contents
  1. What Playwright assertions let through
  2. What about toHaveScreenshot()?
  3. Adding render comparison with the Delta-QA Vision SDK
  4. What happens when a difference appears?
  5. Playwright assertions or Vision SDK: the table
  6. FAQ

Playwright assertions (toBeVisible(), toHaveText(), toBeEnabled()) check the state of the DOM: an element exists, it has a size, it carries the right text. They do not tell you whether that text is readable, whether a banner covers it, or whether the page looks different from the last release. The pipeline goes green, and the defect ships to production.

The scenario is common. A CSS variable changes in the design system, the cart total takes the color of the background, and the three expect calls in the checkout test stay green. None of them was wrong: they checked what they were asked to check. To see this defect, you have to look at the real render and compare it with its previous version. That is the job of a regression test that compares screens, on top of assertions.

What Playwright assertions let through

A Playwright assertion answers one precise question about one element. Anything outside the question passes. The Playwright documentation says so for visibility: an element is visible when it has a non-empty bounding box and no visibility:hidden, and elements with opacity:0 are considered visible (Playwright, Actionability).

Take a perfectly correct checkout test:

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

test('order summary shows the total', async ({ page }) => {
  await page.goto('https://shop.example.com/checkout');
  await expect(page.getByRole('heading', { name: 'Order summary' })).toBeVisible();
  await expect(page.getByTestId('order-total')).toHaveText('€129.00');
  await expect(page.getByRole('button', { name: 'Pay' })).toBeEnabled();
});

Here are three ways to break this page without failing this test.

An element that is present, but covered

A promotional banner switches to position: absolute and covers the order summary. The total still has its box and its text: toBeVisible() and toHaveText() pass. Playwright would refuse to click an element that is covered, but this test does not click the total. It reads it in the DOM, under the banner.

A color or contrast that changes

/* tokens.css, release 4.2: the price now uses the surface token */
.order-total { color: var(--color-surface); }

The amount now displays white on white. The text is still "€129.00", so the assertion passes. You can add toHaveCSS('color', 'rgb(17, 24, 39)'), but that assertion covers a single property of a single element. The background of the block, the neighboring button, or the dark theme stay out of scope.

A layout drift

A changed gap in a grid pushes the "Pay" button below the form footer, or shifts the columns of the summary. The button is enabled, the text is right. To catch it with assertions, you would have to check the positions and sizes of every block, and rewrite those values after each intended change.

What about toHaveScreenshot()?

Playwright also compares screenshots with toHaveScreenshot(). It is a real image comparison for automated tests, free and built in. It has three costs that teams discover in practice.

  • Binary files in Git. Each reference is a versioned PNG. Two branches that change the same page produce a conflict that no merge tool can resolve: you regenerate.
  • One reference per platform. File names carry the browser and the system (-chromium-darwin.png). The documentation warns that rendering varies with the operating system, version, hardware and headless mode (Playwright, Visual comparisons). A reference taken on a Mac is not valid on a Linux CI.
  • A pixel diff. The report shows a red area. It is up to you to guess which element moved and whether the maxDiffPixelRatio threshold hides a real defect. Our guide to toHaveScreenshot() details these settings.

Adding render comparison with the Delta-QA Vision SDK

The Delta-QA Vision SDK (@delta-qa/vision, open source, in beta on npm) adds a named checkpoint to an existing Playwright test. Your assertions stay. The test opens a verification, then calls check() where the page must be compared.

import { expect } from '@playwright/test';
import { test } from '@delta-qa/vision/fixture';

// The run, read in the CI variables (here GitHub Actions)
const run = {
  commit: process.env.GITHUB_SHA!,
  tag: process.env.GITHUB_REF_TYPE === 'tag' ? process.env.GITHUB_REF_NAME! : null,
  branch: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || null,
  baseBranch: process.env.GITHUB_BASE_REF || null,
};

test('order summary shows the total', async ({ page, vision }) => {
  const checkout = await vision.open(page, { id: 'checkout', name: 'Checkout', ...run });
  await page.goto('https://shop.example.com/checkout');
  await expect(page.getByTestId('order-total')).toHaveText('€129.00');
  await checkout.check('Payment');
}); // closed by the fixture: a difference to judge fails the test

The SDK reads the key from the DELTAQA_API_KEY variable. On the first run, each check becomes the reference, stored in Delta-QA and not in the repository.

What happens when a difference appears?

The test fails, and you decide between regression and enhancement, in a report that names the modified element.

The decision flow

  1. Comparison. Delta-QA compares the page the way the human eye would, spots the elements that changed and names them. For the same two renders, the verdict is the same on every run: no learned model runs at execution time.
  2. Failure and link. An unjudged difference fails the test, and the error message gives the link to the report.
  3. Qualification. In the report, you qualify each difference: “Regression” or “Enhancement”.
  4. Update. A difference qualified as “Enhancement” becomes the new reference for the branches you tick. The history keeps the previous versions.

The comparison is validated on 458 published test cases: RGB, HSL and OKLCH colors, dark theme, form states, and DOM changes with no effect on screen, which must not be reported.

What to know

  • Three browsers. Your Playwright test opens the page in Chrome. Delta-QA then verifies it in Chrome, Firefox and Safari, without you running your test three times.
  • One reference per screen size. If your Playwright projects test a desktop and a mobile, each size has its own reference.
  • Content that changes on every run. An order number or a date differs on each execution. Exclude them from the check with ignore: [locator], otherwise every run reports a difference.

Around the SDK

The Delta-QA MCP server lets your coding agent (Claude Code, Codex, Cursor, VS Code) prepare scenarios, which Delta-QA replays and compares. Scenarios recorded without code and SDK checks are judged in the same space. Delta-QA, designed in France, is used as SaaS or On-Premise.

Playwright assertions or Vision SDK: the table

The two complement each other: assertions verify the logic, the comparison verifies the screen.

Criterion Native Playwright assertions Delta-QA (Vision SDK)
What is verified DOM state: presence, text, attributes, named properties Real render of the page, compared with its reference
Covered element Passes if the box exists Flagged: the render changed
Color, contrast, theme Only the properties written in toHaveCSS() The whole page compared
Layout Positions to code one by one Shifts spotted and named
References None, or PNGs in Git with toHaveScreenshot() Stored in Delta-QA, per branch, with history
Reading a difference Assertion message, or a red pixel area Report that names the modified element
Handling a difference Fix the test or regenerate the PNGs “Regression” or “Enhancement”, the reference follows
Maintenance Assertions to rewrite at every interface change One named check per screen, judged in the report

FAQ

Do Playwright assertions detect visual regressions?

No, not directly. They check the DOM: an element can be present, visible in Playwright's sense and carry the right text while being covered or unreadable. Only a comparison of the render with its reference sees these defects.

Do I need to rewrite my Playwright tests to use the Vision SDK?

No. The test keeps its actions and its assertions. You import test from @delta-qa/vision/fixture, open the verification and add a named check() where the page must be compared.

What is the difference with toHaveScreenshot()?

toHaveScreenshot() compares pixels against a PNG versioned in Git, one reference per platform. The Vision SDK stores the references in Delta-QA, per branch, and the report names the element that changed.

Does Delta-QA verify the page on Firefox and Safari?

Yes: Delta-QA verifies the page in Chrome, Firefox and Safari. Your Playwright test, for its part, runs in Chrome, Chromium or Edge, and your assertions stay unchanged.

Try Delta-QA