Menu

What Playwright's toHaveScreenshot() default lets through: threshold, maxDiffPixels and ratio tested on 11 changes
📰

What Playwright's toHaveScreenshot() default lets through: threshold, maxDiffPixels and ratio tested on 11 changes

DEV Community: javascript·CurlShot·2 days ago
#PSrLUV6t
#devtojavascript#devto#dev#ddd#fail
Reading 0:00
15s threshold

A visual test that never fails is worse than none. I wanted to know what toHaveScreenshot() in Playwright lets through with its default settings, so I built one small card (heading, price, button, gradient), made eleven small changes to it and compared each change to a baseline under five option sets. The results are not what the option names suggest.

Setup: @playwright/test 1.63.0 with its Chromium headless shell, Node v24.22.3, Linux, run on 2026-11-13. The page is served from a local HTTP server and the font is DejaVu Sans, so nothing depends on a remote site. Viewport is 800 x 500.

The test

Config first:

module . exports = { testDir : './tests' , workers : 1 , reporter : 'line' , snapshotPathTemplate : '{testDir}/__shots__/{arg}{ext}' , use : { viewport : { width : 800 , height : 500 } } , } ;

Enter fullscreen mode

Exit fullscreen mode

Save the next file as tests/vr.spec.js .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.