[Docs]: maxDiffPixels: 0 is not an exact comparison — say that threshold still applies
Page(s)
- https://playwright.dev/docs/next/api/class-locatorassertions (
toHaveScreenshot,maxDiffPixelsandmaxDiffPixelRatiooptions) - https://playwright.dev/docs/next/api/class-pageassertions (same options)
- https://playwright.dev/docs/next/test-snapshots
- Source:
docs/src/api/params.md,## assertions-max-diff-pixelsand## assertions-max-diff-pixel-ratio
Description
expect(locator).toHaveScreenshot(name[, options]) and expect(page).toHaveScreenshot(name[, options])
The maxDiffPixels entry reads "An acceptable amount of pixels that could be different." That makes maxDiffPixels: 0 read like an exact comparison. It is not: a pixel only counts as different once its colour moves by more than threshold, which defaults to 0.2. So with maxDiffPixels: 0 alone, every pixel may still drift by up to 0.2 in YIQ distance and the assertion passes.
At 0.2 that is enough to hide real changes. In our suite a faint card border read as the background behind it: a baseline passed against a build with the fix reverted, and failed with 1317 px once threshold was set to 0.1. A second case: two text colours (#454039 and #6e6860) compared equal at the default. Our config set maxDiffPixels: 0 and described it in a comment as "zero tolerance".
The threshold entry is accurate; the trap is that nothing in the maxDiffPixels or maxDiffPixelRatio entries says the two work together. Suggested addition to both:
A pixel counts as different only when its colour differs by more than
threshold(default0.2), somaxDiffPixels: 0does not make the comparison exact. Setthresholdtoo for a stricter comparison.
A sentence to the same effect in the "Visual comparisons" guide, near the maxDiffPixels example, would help as well, since that is where most configs are copied from.
Source: microsoft/playwright