From 1ee243056477a617e4023e23002dba64cf999e31 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 23:09:34 +1300 Subject: [PATCH] Deterministic screenshots: scroll once the page settles, and compare pixels before hunting a cause (what DocSpring's flaky specs taught us, sc-8843); plugin 0.1.39 --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- .cursor-plugin/plugin.json | 2 +- gemini-extension.json | 2 +- .../content/docs/screenshots/deterministic.md | 26 ++++++++++++++++++- skills/visualci-deterministic/SKILL.md | 26 ++++++++++++++++++- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 0cbdedf3..e14be583 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.42", + "version": "0.1.43", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 91827860..dda1b1b7 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.42", + "version": "0.1.43", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 940faebe..e3a95810 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.42", + "version": "0.1.43", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring" diff --git a/gemini-extension.json b/gemini-extension.json index c86b69a8..e09f73da 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.42", + "version": "0.1.43", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "mcpServers": { "visualci": { diff --git a/server/frontend/content/docs/screenshots/deterministic.md b/server/frontend/content/docs/screenshots/deterministic.md index 7b3dd779..59626ac8 100644 --- a/server/frontend/content/docs/screenshots/deterministic.md +++ b/server/frontend/content/docs/screenshots/deterministic.md @@ -24,6 +24,7 @@ as a change somebody has to look at. Fix these in the tests, once, rather than a | Lazy-loaded images | Wait for every image to finish loading | | Viewport, scrollbars, pixel ratio | Fix the viewport size, hide scrollbars, use a device pixel ratio of 1 | | Text cursor, hover, focus | Hide the caret, and move the mouse away | +| Scroll position | Scroll once the page has stopped changing, never while it still lays out | What's left after this (anti-aliasing that differs slightly between runs) is what a [threshold](/docs/screenshots/#thresholds) is for. A threshold can't fix a clock or an animation: those change far @@ -40,7 +41,13 @@ diff <(cd run1 && find . -name '*.png' | sort | xargs sha256sum) \ <(cd run2 && find . -name '*.png' | sort | xargs sha256sum) ``` -Run it in CI's image, since that's where the baselines come from. +Run it in CI's image, since that's where the baselines come from. Run it more than twice when a difference comes and +goes: five or more runs show whether a screenshot has two versions or a different one every time. + +If files differ but look the same, compare their pixels before hunting for a cause: a tool that crops or resizes a +screenshot (ImageMagick does) can write the time into the PNG, so the same pixels make a different file on every run. +VisualCI compares pixels, so those show as unchanged; strip the timestamp (`magick … -strip -define +png:exclude-chunks=date,time`) to make the files themselves the same. VisualCI points at likely suspects too: a change whose content flipped back and forth over its branch's recent builds (A, B, A, B) is marked **flaky?** on the build page and `flaky: true` in `get_build`. It's only a hint: nothing is @@ -116,6 +123,23 @@ purpose: a screenshot from a Retina laptop is twice the size of one from CI). Hi operating systems and appear only when content overflows. Hide the text cursor, and move the mouse away from anything with a hover state. +### Scroll position + +A test that scrolls an element into view before the screenshot gets a different scroll position on each run when the +page is still laying out: a banner appearing, an image loading above the element, a font arriving late. Both the +window and any box that scrolls inside the page move, so the whole screenshot shifts by a few pixels. Wait for the +page to stop changing (fonts loaded, no more layout), then scroll, then take the screenshot. Scroll the window back to +the top first, so the starting point is the same every time: + +```js +await page.evaluate(() => document.fonts.ready) +// ... wait until the page stops changing ... +await page.evaluate((selector) => { + window.scrollTo(0, 0) + document.querySelector(selector).scrollIntoView({ block: 'center', behavior: 'instant' }) +}, '#signature') +``` + ## Playwright Most of this is configuration. In `playwright.config.ts`: diff --git a/skills/visualci-deterministic/SKILL.md b/skills/visualci-deterministic/SKILL.md index 398ddd82..3f0ab18c 100644 --- a/skills/visualci-deterministic/SKILL.md +++ b/skills/visualci-deterministic/SKILL.md @@ -29,6 +29,7 @@ as a change somebody has to look at. Fix these in the tests, once, rather than a | Lazy-loaded images | Wait for every image to finish loading | | Viewport, scrollbars, pixel ratio | Fix the viewport size, hide scrollbars, use a device pixel ratio of 1 | | Text cursor, hover, focus | Hide the caret, and move the mouse away | +| Scroll position | Scroll once the page has stopped changing, never while it still lays out | What's left after this (anti-aliasing that differs slightly between runs) is what a [threshold](https://visualci.com/docs/screenshots.md#thresholds) is for. A threshold can't fix a clock or an animation: those change far @@ -45,7 +46,13 @@ diff <(cd run1 && find . -name '*.png' | sort | xargs sha256sum) \ <(cd run2 && find . -name '*.png' | sort | xargs sha256sum) ``` -Run it in CI's image, since that's where the baselines come from. +Run it in CI's image, since that's where the baselines come from. Run it more than twice when a difference comes and +goes: five or more runs show whether a screenshot has two versions or a different one every time. + +If files differ but look the same, compare their pixels before hunting for a cause: a tool that crops or resizes a +screenshot (ImageMagick does) can write the time into the PNG, so the same pixels make a different file on every run. +VisualCI compares pixels, so those show as unchanged; strip the timestamp (`magick … -strip -define +png:exclude-chunks=date,time`) to make the files themselves the same. VisualCI points at likely suspects too: a change whose content flipped back and forth over its branch's recent builds (A, B, A, B) is marked **flaky?** on the build page and `flaky: true` in `get_build`. It's only a hint: nothing is @@ -121,6 +128,23 @@ purpose: a screenshot from a Retina laptop is twice the size of one from CI). Hi operating systems and appear only when content overflows. Hide the text cursor, and move the mouse away from anything with a hover state. +### Scroll position + +A test that scrolls an element into view before the screenshot gets a different scroll position on each run when the +page is still laying out: a banner appearing, an image loading above the element, a font arriving late. Both the +window and any box that scrolls inside the page move, so the whole screenshot shifts by a few pixels. Wait for the +page to stop changing (fonts loaded, no more layout), then scroll, then take the screenshot. Scroll the window back to +the top first, so the starting point is the same every time: + +```js +await page.evaluate(() => document.fonts.ready) +// ... wait until the page stops changing ... +await page.evaluate((selector) => { + window.scrollTo(0, 0) + document.querySelector(selector).scrollIntoView({ block: 'center', behavior: 'instant' }) +}, '#signature') +``` + ## Playwright Most of this is configuration. In `playwright.config.ts`: