Skip to main content
This page covers web only, including mobile web using Playwright emulators.
To perform a visual comparison, use toHaveScreenshot.
  • name — string used to identify and store the baseline image
  • options — optional object controlling comparison behavior, see Key options below

Examples

Assert a canvas element:
Assert a specific UI component:
Assert a full page:
Omitting a name and maxDiffPixelRatio makes the baseline hard to identify and causes minor rendering differences to fail the test.

When to use

  • Your test needs to assert the content or appearance of a canvas element — canvas is not part of the DOM and cannot be targeted with locators.
  • You want to catch layout or style regressions after a redesign or component change.
  • No selector or functional assertion can verify the visual state you need.
  • Your app has pixel-perfect design requirements, and you want automated enforcement.
Avoid toHaveScreenshot when the area contains timestamps, live data, animations, or other frequently-changing content — these cause false failures. Use a functional assertion instead.

Key options

Notes

  • On the first run, no baseline exists yet — the screenshot is saved automatically as the expected image. Review it before relying on the test.
  • The editor shows the diff, the expected image, and the actual image for each named snapshot, and compares them.
  • On subsequent runs, a new screenshot is compared pixel-by-pixel to the baseline. If the difference exceeds the threshold, the test fails, and a diff image is saved showing exactly which pixels changed.
  • If a UI change is intentional, promote the new screenshot as the updated baseline in the QA Wolf editor. Future runs will compare against the new image.

Full sample test

Last modified on December 4, 2026