Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion .cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gemini-extension.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
26 changes: 25 additions & 1 deletion server/frontend/content/docs/screenshots/deterministic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`:
Expand Down
26 changes: 25 additions & 1 deletion skills/visualci-deterministic/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`:
Expand Down
Loading