<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kirill</title>
    <description>The latest articles on DEV Community by Kirill (@marshlw).</description>
    <link>https://dev.to/marshlw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4226159%2F467845bf-d002-445b-8165-51a0bf1500b2.jpg</url>
      <title>DEV Community: Kirill</title>
      <link>https://dev.to/marshlw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marshlw"/>
    <language>en</language>
    <item>
      <title>The underline my visual tests couldn't see</title>
      <dc:creator>Kirill</dc:creator>
      <pubDate>Tue, 24 Nov 2026 18:18:15 +0000</pubDate>
      <link>https://dev.to/marshlw/the-underline-my-visual-tests-couldnt-see-a38</link>
      <guid>https://dev.to/marshlw/the-underline-my-visual-tests-couldnt-see-a38</guid>
      <description>&lt;p&gt;Chromium drew a blue underline under a link. VisTest picked up the changed pixels. The test passed anyway.&lt;/p&gt;

&lt;p&gt;I built VisTest to catch visual regressions in Python Playwright tests. In &lt;a href="https://dev.to/marshlw/my-visual-testing-engine-met-a-real-browser-it-missed-almost-half-the-changes-3ni8"&gt;part 3&lt;/a&gt;, a benchmark made from Chromium screenshots showed how often my engine missed real changes. This one underline showed me where to look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the line went
&lt;/h2&gt;

&lt;p&gt;I traced the changed pixels through the old engine. They made it into the first map of differences. Then a cleanup step erased the thin line before it could become a region the engine would report. By the time VisTest decided whether to pass, there was nothing left to judge. &lt;a href="https://github.com/marshlw/vistest/blob/9cd30b0ad550df84bc0c476c3dca0191b6b9c706/docs/dev/journal.md#L812-L845" rel="noopener noreferrer"&gt;Development journal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A stricter setting at the end of that pipeline had nothing to work with. I rewrote the part that decided which pixels made it that far.&lt;/p&gt;

&lt;h2&gt;
  
  
  What v2 does with the same screenshot
&lt;/h2&gt;

&lt;p&gt;The new engine groups changed pixels into regions first. Then it looks for a specific reason to set a region aside. One rule checks whether slightly different text edges can be explained by how the browser drew the same letters. When a rule suppresses a region, the result records which rule did it.&lt;/p&gt;

&lt;p&gt;On those same two PNGs, v2 fails the check and tells me where to look.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;changed:     57x1 at (37, 182): line added: 57×1 px, #2563eb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fynyuubyif5u4jzx68bo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fynyuubyif5u4jzx68bo2.png" alt="Three enlarged crops show order link #10421 before and after an underline was added, and the line marked by VisTest." width="800" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The same crop from the baseline, the changed screenshot and the diff VisTest generated.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are still false alarms. A chart drawn at a fractional pixel offset can come back with different edges and fail a check even when the data is the same. Those cases are in the &lt;a href="https://github.com/marshlw/vistest/blob/9cd30b0ad550df84bc0c476c3dca0191b6b9c706/docs/GUIDE.md#what-engine-v2-does-not-tell-apart" rel="noopener noreferrer"&gt;VisTest guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the same comparison
&lt;/h2&gt;

&lt;p&gt;Save the &lt;a href="https://raw.githubusercontent.com/marshlw/vistest/9cd30b0ad550df84bc0c476c3dca0191b6b9c706/tests/browser_corpus/frames/table/base.png" rel="noopener noreferrer"&gt;baseline&lt;/a&gt; and &lt;a href="https://raw.githubusercontent.com/marshlw/vistest/9cd30b0ad550df84bc0c476c3dca0191b6b9c706/tests/browser_corpus/frames/table/underline--on.png" rel="noopener noreferrer"&gt;changed screenshot&lt;/a&gt; in one directory. The example uses VisTest &lt;code&gt;0.2.0a5&lt;/code&gt; and OpenCV &lt;code&gt;5.0.0&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install &lt;span class="nv"&gt;vistest&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;0.2.0a5
vistest compare base.png underline--on.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command exits with code &lt;code&gt;1&lt;/code&gt; for this pair and writes the diff to &lt;code&gt;vistest-diff/&lt;/code&gt;. You can also give it two screenshots of your own. For pytest and Playwright, there's a runnable example of the same comparison in a test with &lt;code&gt;expect_screenshot()&lt;/code&gt;. &lt;a href="https://github.com/marshlw/vistest#a-fuller-example" rel="noopener noreferrer"&gt;VisTest on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've ever had a screenshot test stay green after a visible UI change, what did it miss?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://marshlw-blog.hashnode.dev/the-underline-my-visual-tests-couldn-t-see" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt;. Drafted with AI using the VisTest development journal and a verified CLI run.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>playwright</category>
      <category>opensource</category>
    </item>
    <item>
      <title>My visual-testing engine met a real browser. It missed almost half the changes.</title>
      <dc:creator>Kirill</dc:creator>
      <pubDate>Wed, 18 Nov 2026 12:48:29 +0000</pubDate>
      <link>https://dev.to/marshlw/my-visual-testing-engine-met-a-real-browser-it-missed-almost-half-the-changes-3ni8</link>
      <guid>https://dev.to/marshlw/my-visual-testing-engine-met-a-real-browser-it-missed-almost-half-the-changes-3ni8</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 3 of a series about building &lt;a href="https://github.com/marshlw/vistest" rel="noopener noreferrer"&gt;VisTest&lt;/a&gt;, an open-source visual regression library for pytest and Playwright. &lt;a href="https://marshlw-blog.hashnode.dev/i-measured-my-visual-testing-engine-with-a-ruler-i-drew-myself" rel="noopener noreferrer"&gt;Part 2&lt;/a&gt; was about measuring the engine with a ruler I drew myself. This one is about replacing the ruler.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I built a frozen corpus from six pages rendered by Chromium, with changes and expected answers written down before measuring the engine.&lt;/li&gt;
&lt;li&gt;On the September 2026 corpus, the old VisTest engine missed 132 of 276 real changes. Playwright's default comparator missed 103. At &lt;code&gt;threshold: 0.05&lt;/code&gt;, it missed 22.&lt;/li&gt;
&lt;li&gt;My engine produced fewer false failures, but it was throwing away entire families of real changes: text colors, underlines, focus rings.&lt;/li&gt;
&lt;li&gt;Making the screenshots repeatable took work of its own. Even a mutation applied at the wrong moment could change the pixels.&lt;/li&gt;
&lt;li&gt;The useful result was a list of things the engine could not see, and a way to check whether a fix helped on pages it had not been tuned on.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The table I did not want to publish
&lt;/h2&gt;

&lt;p&gt;At the end of the previous article, I had run a small probe on one Chromium page. It was enough to make the synthetic benchmark uncomfortable. It was not enough to replace it.&lt;/p&gt;

&lt;p&gt;One page still lets me choose the layout, the changes and the explanation afterwards. I needed more pages, a repeatable capture, and rules I could not quietly move when the numbers arrived.&lt;/p&gt;

&lt;p&gt;Here is where that led:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool and setting&lt;/th&gt;
&lt;th&gt;False failures, out of 48 noise pairs&lt;/th&gt;
&lt;th&gt;Missed changes, out of 276 signal pairs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;VisTest, balanced&lt;/td&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;132&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playwright, default (&lt;code&gt;threshold: 0.2&lt;/code&gt;, &lt;code&gt;maxDiffPixels: 0&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;42&lt;/td&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playwright, &lt;code&gt;threshold: 0.05&lt;/code&gt;, &lt;code&gt;maxDiffPixels: 0&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;42&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are historical results from 28 September 2026, before engine v2. VisTest was measured with OpenCV 4.13.0; the native Playwright comparator was 1.63.0. The recorded command was &lt;code&gt;python tests/benchmark.py --corpus browser --no-timing --markdown docs/benchmark_browser.md&lt;/code&gt;. The &lt;a href="https://github.com/marshlw/vistest/blob/8928772f3be7cd11e99dced487afb6687b662ee6/docs/benchmark_browser.md" rel="noopener noreferrer"&gt;archived table&lt;/a&gt; and &lt;a href="https://github.com/marshlw/vistest/blob/8928772f3be7cd11e99dced487afb6687b662ee6/docs/dev/journal.md" rel="noopener noreferrer"&gt;development journal&lt;/a&gt; preserve this stage. Running the command on today's engine measures today's engine, not this table.&lt;/p&gt;

&lt;p&gt;My default missed nearly half the real changes. Playwright's stricter setting caught far more of them, while failing on eight more noise pairs.&lt;/p&gt;

&lt;p&gt;There is no single winner hidden in those two columns. But there was a very clear problem with the product I was building.&lt;/p&gt;

&lt;h2&gt;
  
  
  Six pages, with the answers written first
&lt;/h2&gt;

&lt;p&gt;The new corpus started with six small local pages: an orders table, a settings form, product cards, a landing page, a long serif article and a dark dashboard.&lt;/p&gt;

&lt;p&gt;They were still pages I wrote. This was not a random sample of production websites, and rendering them in Chromium did not make them independent of every assumption I had. It did remove one important dependency: OpenCV no longer drew the pictures that my OpenCV-based engine was being judged on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faj2g7gcbbn5wt2twq1l0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faj2g7gcbbn5wt2twq1l0.png" alt="The six actual baseline pages in the browser corpus" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The frozen Chromium baselines, shown as thumbnails. These are the corpus pages, not illustrations of them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Each page had targets for the same families of changes. Repaint a button. Change a link color. Add an underline. Remove a border. Change one character. Move a block. Make text bold. Remove an element.&lt;/p&gt;

&lt;p&gt;The expected answer came from the operation that made the screenshot. If I changed one character, the pair was a real change whether my engine found it or not.&lt;/p&gt;

&lt;p&gt;Some cases needed a human decision. I made those decisions before measuring:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Change&lt;/th&gt;
&lt;th&gt;Corpus label&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Color difference around ΔE00 2&lt;/td&gt;
&lt;td&gt;DISPUTED&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A block moved by 1 px&lt;/td&gt;
&lt;td&gt;SIGNAL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opacity reduced to 0.98&lt;/td&gt;
&lt;td&gt;NOISE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Letter spacing increased by 0.2 px&lt;/td&gt;
&lt;td&gt;SIGNAL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Those labels are a policy, not a law of vision. A design-system test might care about that opacity change. Another team might accept the spacing change. What mattered here was that my engine's answer did not get a vote in the label.&lt;/p&gt;

&lt;p&gt;DISPUTED cases stayed in the corpus and in the output, outside the score. I wanted to see how the tools treated them without turning a borderline judgment into a claimed win.&lt;/p&gt;

&lt;p&gt;Even the color changes had a separate ruler. The generator calculated them with its own implementation of CIEDE2000, checked against published reference pairs, rather than importing the engine's color-distance function. After rounding colors to eight bits, it recorded the distance it actually produced.&lt;/p&gt;

&lt;p&gt;The previous corpus had taught me what happens when the generator and detector share the same mistake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before testing the engine, I had to test the camera
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What I thought.&lt;/strong&gt; Local HTML, a pinned Chromium, no network. Take a screenshot and move on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happened.&lt;/strong&gt; Two fresh browsers could draw different pixels for the same case.&lt;/p&gt;

&lt;p&gt;The control was simple: draw each frame in two separately started browsers. If the pictures differed, stop. A frame that could not reproduce itself had no business deciding whether a comparator was correct.&lt;/p&gt;

&lt;p&gt;That control caught three problems before the benchmark caught anything useful about the engine.&lt;/p&gt;

&lt;p&gt;First, applying a mutation after page load was too late. Depending on timing, Chromium could paint before or after the change. A fill mutation came out seven pixels different in the second browser. Moving the mutation to &lt;code&gt;DOMContentLoaded&lt;/code&gt;, before the first paint, made the operation repeatable.&lt;/p&gt;

&lt;p&gt;Second, rendering styles needed to exist from the first paint too. A fractional shift on the dark page sometimes differed between captures. Waiting longer afterwards did not fix the fact that the two pages had started rendering differently.&lt;/p&gt;

&lt;p&gt;Third, a focus outline on a text input could move a corner pixel between frames. The corpus used a button for that mutation instead. The purpose was to measure whether an engine detected a focus ring, with a frame whose pixels were repeatable.&lt;/p&gt;

&lt;p&gt;There was a quieter mistake as well. The first version of a movement case changed &lt;code&gt;margin-top&lt;/code&gt;. On the article template the margin collapsed, and the target did not move. The final case used padding. A line of CSS saying “move this” is not evidence that anything moved.&lt;/p&gt;

&lt;h2&gt;
  
  
  A bundled font is not proof that it was used
&lt;/h2&gt;

&lt;p&gt;The pages shipped their fonts. They loaded nothing from the network. I gave the font families their own names so a locally installed font would not accidentally take their place.&lt;/p&gt;

&lt;p&gt;Then I asked Chromium which fonts it had actually drawn.&lt;/p&gt;

&lt;p&gt;One character, &lt;code&gt;›&lt;/code&gt;, had fallen back to Liberation Sans.&lt;/p&gt;

&lt;p&gt;The stylesheet was correct. The screenshot was not using only the fonts I thought it was using. Checking the fonts through Chrome's DevTools Protocol caught what checking the CSS could not.&lt;/p&gt;

&lt;p&gt;The environment record grew accordingly: operating system, architecture, Playwright version, Chromium version and build, viewport, device scale factor, and the fonts actually used on each page.&lt;/p&gt;

&lt;p&gt;Even &lt;code&gt;browser.version&lt;/code&gt; was not enough to distinguish the full Chromium executable from its headless shell. They could report the same version and render text differently. The record needed the browser product string as well.&lt;/p&gt;

&lt;p&gt;I was building a benchmark for image comparison and spending my time proving where an image came from. That turned out to be part of the benchmark.&lt;/p&gt;

&lt;h2&gt;
  
  
  Noise had to exist in the pixels
&lt;/h2&gt;

&lt;p&gt;The noise cases kept the content and changed how it was rendered: hinting, text rendering, fractional page shifts, the full browser instead of the headless shell.&lt;/p&gt;

&lt;p&gt;Changing a browser flag was not enough to earn a case. If it produced exactly the baseline pixels, it was recorded as having no effect and left out of the pairs.&lt;/p&gt;

&lt;p&gt;Otherwise I could improve the noise score by adding easy “noise” cases with no differences to detect.&lt;/p&gt;

&lt;p&gt;The first frozen set contained 276 signal pairs, 42 noise pairs and 18 disputed pairs. Adding six Windows baselines later brought the noise count to 48. The table at the start includes that addition.&lt;/p&gt;

&lt;p&gt;The Windows frames used the same Chromium build and the shipped fonts, with the same viewport and scale. They still differed from Linux. Every tested setting of both tools failed on all six pairs.&lt;/p&gt;

&lt;p&gt;That result also put a limit on the earlier one-page probe. In that probe, several renderer variations had produced identical pixels. Here, with different pages and bundled web fonts, some of those variations changed the pictures substantially.&lt;/p&gt;

&lt;p&gt;“This flag did nothing on my page” had been true. “This flag produces no rendering noise” would not have been.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I kept two pages out of reach
&lt;/h2&gt;

&lt;p&gt;Four templates were for calibration: table, form, cards and article. Landing and dark were held out.&lt;/p&gt;

&lt;p&gt;The split was by page, not by screenshot pair.&lt;/p&gt;

&lt;p&gt;If I tuned a rule on a button from the landing page, then tested it on another mutation of the same button, I would still be looking at the same geometry, background and fonts. A random split of pairs would make the test set look separate while carrying much of the training material into it.&lt;/p&gt;

&lt;p&gt;Holding out entire templates was a stronger question: does the rule help on a page it did not get to learn?&lt;/p&gt;

&lt;p&gt;It was not a permanent certificate. Once a held-out result influenced my next choice, that page was no longer an untouched test of the next idea. A folder named “held-out” cannot enforce that distinction for you.&lt;/p&gt;

&lt;p&gt;The manifest stored the split with each pair. The test suite checked it. The remaining part was discipline: choose on the calibration pages, then measure the held-out pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Playwright got more than one setting
&lt;/h2&gt;

&lt;p&gt;It would have been convenient to compare only defaults. My default had fewer false failures, and I could have led with that column.&lt;/p&gt;

&lt;p&gt;Instead, the benchmark ran Playwright's native comparator over a grid: three pixel thresholds and four allowed pixel counts. The recorded comparator was the one used by &lt;code&gt;toHaveScreenshot()&lt;/code&gt;, not a Python approximation of it.&lt;/p&gt;

&lt;p&gt;Those two settings buy different things. Lowering &lt;code&gt;threshold&lt;/code&gt; makes the comparison sensitive to smaller color differences. Raising &lt;code&gt;maxDiffPixels&lt;/code&gt; lets more changed pixels through before the check fails.&lt;/p&gt;

&lt;p&gt;The second setting does not know whether those pixels belong to noisy text or a real underline. It just counts.&lt;/p&gt;

&lt;p&gt;That is why the report kept false failures and misses separate. A setting that saves some noisy checks by hiding more real changes has made a trade, and the table should show both sides of it.&lt;/p&gt;

&lt;p&gt;The browser used to capture the corpus was Python Playwright 1.56.0 with Chromium 141.0.7390.37. The comparator was Playwright 1.63.0. Those are different roles and different recorded versions: one produced the images, the other compared the frozen pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The useful part was below the headline
&lt;/h2&gt;

&lt;p&gt;The summary told me the engine had a problem. The table by change family told me where to look.&lt;/p&gt;

&lt;p&gt;The old balanced engine missed every text-color, link-color and icon-color case. It missed every added underline, focus ring and removed border.&lt;/p&gt;

&lt;p&gt;These were not all subtle changes at the edge of perception. The color families included ΔE00 15.&lt;/p&gt;

&lt;p&gt;On the failures inspected in the journal, the changed pixels existed in the intermediate mask. They did not survive into a region. The engine returned zero regions for a real change it had already seen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffkqxhs1x1qts4seymuor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffkqxhs1x1qts4seymuor.png" alt="Four-times enlarged crops of the actual baseline and underline mutation" width="799" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Baseline on the left, the frozen underline mutation on the right. Identical crops enlarged 4× with nearest-neighbor scaling; no pixels retouched. The historical family table records that VisTest missed this family on every template.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That was a different diagnosis from “the threshold needs adjusting.” A threshold at the end cannot recover evidence discarded earlier in the pipeline.&lt;/p&gt;

&lt;p&gt;The cascade had accumulated ways to keep checks green: consensus between color and structure, anti-aliasing suppression, morphological cleanup, minimum sizes. Each had a reason. Together, on real browser text and thin edges, they could erase the thing the tool existed to find.&lt;/p&gt;

&lt;p&gt;Making the preset stricter helped some cases. It did not make that design sound.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this corpus could still not prove
&lt;/h2&gt;

&lt;p&gt;The renderer was real. The pages and mutations were mine.&lt;/p&gt;

&lt;p&gt;Six local pages do not represent every application. The labels encode my decisions. A corpus with many rendering variations does not tell you how often those variations occur in a team's pinned CI environment. Its false-failure percentage is a percentage of these deliberately selected pairs, not a forecast for your next thousand tests.&lt;/p&gt;

&lt;p&gt;And a comparison of frozen images does not measure the entire screenshot-testing experience: waiting for the application, dealing with animation, choosing baselines, reading a failure and deciding what to accept.&lt;/p&gt;

&lt;p&gt;This corpus gave me a better experiment. Calling it “real browser” did not make it the real world.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed after the cold shower
&lt;/h2&gt;

&lt;p&gt;I stopped treating fewer red checks as evidence of a better engine on its own.&lt;/p&gt;

&lt;p&gt;The next design started from a different requirement: keep the visible differences, then ask which ones a specific rule can explain. A difference should not disappear just because it is small or inconvenient to classify. If a rule sets it aside, the result should name that rule.&lt;/p&gt;

&lt;p&gt;That became engine v2. The installed library today uses it by default; the old-engine table above is the reason for the rewrite, not a report on the current release.&lt;/p&gt;

&lt;p&gt;The rewrite and its remaining failures deserve their own article. This stage ended with the engine untouched and a much less flattering measurement of it.&lt;/p&gt;

&lt;p&gt;That was progress. I finally had a benchmark capable of telling me to stop.&lt;/p&gt;

&lt;p&gt;If you are building a testing tool, try one thing before adding the next feature: take a failure family your own tests barely cover, write down the expected answers, and measure it without changing the implementation. Keep the table even if it makes the launch post harder to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it on a page I did not write
&lt;/h2&gt;

&lt;p&gt;If your team already has screenshot tests, you probably have a better next experiment than another page I could add to my corpus: your own baseline/actual pairs.&lt;/p&gt;

&lt;p&gt;You can try the current engine on those pictures before changing any tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install vistest
vistest bench --expected baselines --actual screenshots
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two folders should contain matching file names. If you already use Playwright Test, &lt;code&gt;vistest bench test-results&lt;/code&gt; reads its output layout instead.&lt;/p&gt;

&lt;p&gt;The command writes a local HTML report showing where VisTest and Playwright disagree. The Playwright comparison needs Node.js and an installed &lt;code&gt;@playwright/test&lt;/code&gt;; &lt;code&gt;--no-playwright&lt;/code&gt; runs VisTest alone. The screenshots stay on your machine.&lt;/p&gt;

&lt;p&gt;Pick a few pairs where you know what happened: an intentional UI change, a rendering difference that wasted your time, a defect your old check missed. Look at the explanation as well as the verdict. Would it have helped you decide what to do?&lt;/p&gt;

&lt;p&gt;I'm looking for a few teams using pytest and Playwright to try this on an existing project. If that sounds useful, leave a comment or &lt;a href="https://github.com/marshlw/vistest/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt; with your setup and what you found. You do not need to post private screenshots; a description is enough to start. I'd like to help investigate the disagreements, including the ones where VisTest is wrong.&lt;/p&gt;

&lt;p&gt;The next useful result is a check someone else understands and keeps running. Another green table on my own pages cannot tell me that.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Next: rebuilding the engine so a difference needs an explanation before it can disappear.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>automation</category>
      <category>opensource</category>
      <category>python</category>
      <category>testing</category>
    </item>
    <item>
      <title>I measured my visual-testing engine with a ruler I drew myself</title>
      <dc:creator>Kirill</dc:creator>
      <pubDate>Mon, 09 Nov 2026 16:05:09 +0000</pubDate>
      <link>https://dev.to/marshlw/i-measured-my-visual-testing-engine-with-a-ruler-i-drew-myself-548j</link>
      <guid>https://dev.to/marshlw/i-measured-my-visual-testing-engine-with-a-ruler-i-drew-myself-548j</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 2 of a series about building &lt;a href="https://github.com/marshlw/vistest" rel="noopener noreferrer"&gt;VisTest&lt;/a&gt;, an open-source visual regression library for pytest and Playwright. &lt;a href="https://dev.to/marshlw/playwright-for-python-has-no-tohavescreenshot-so-i-wrote-a-visual-testing-library-1fe5"&gt;Part 1&lt;/a&gt; was about why I started it. This one is about the month I spent fooling myself with a perfect score.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My comparison engine scored &lt;strong&gt;54/54&lt;/strong&gt; on my own benchmark: 0 false failures, 0 missed changes. Playwright's &lt;code&gt;toHaveScreenshot()&lt;/code&gt; scored 38/54, pixelmatch 34/54.&lt;/li&gt;
&lt;li&gt;The number was real. It was also close to worthless, because the benchmark was drawn by the same library, by the same person, with the same assumptions that set the engine's thresholds.&lt;/li&gt;
&lt;li&gt;Along the way I found four ways a benchmark lies: a score that depended on the installed OpenCV, an engine that printed a shift it never drew, a test case that never existed, and a JPEG case that passed because of swapped color channels.&lt;/li&gt;
&lt;li&gt;On one real Chromium page, the same day, the picture looked completely different.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The perfect score
&lt;/h2&gt;

&lt;p&gt;By late September VisTest had a benchmark I was proud of. A table, generated by a script, with every tool running on its default settings:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;False failures&lt;/th&gt;
&lt;th&gt;Missed changes&lt;/th&gt;
&lt;th&gt;Correct&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;VisTest&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0/32&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0/22&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;54/54&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playwright 1.63 &lt;code&gt;toHaveScreenshot()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;14/32&lt;/td&gt;
&lt;td&gt;2/22&lt;/td&gt;
&lt;td&gt;38/54&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pixelmatch 7.2.0&lt;/td&gt;
&lt;td&gt;18/32&lt;/td&gt;
&lt;td&gt;2/22&lt;/td&gt;
&lt;td&gt;34/54&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Thirty-two pairs where nothing meaningful changed (sensor noise, sub-pixel text, a JPEG re-encode, a scroll bar) and the test should stay green. Twenty-two pairs with a real change (a price, a button, a header color) where it should go red. My engine got every single one right.&lt;/p&gt;

&lt;p&gt;If I had stopped there, this would be a launch post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the ruler came from
&lt;/h2&gt;

&lt;p&gt;The corpus came from a script, &lt;code&gt;tests/synthetic.py&lt;/code&gt;. It draws a fake shop page with OpenCV: a header, a product card, a "Buy now" button, a promo banner. Then it draws variations of it: add noise, re-encode as JPEG, change the price, repaint the header. 27 cases, each drawn on two OpenCV versions, 54 pairs.&lt;/p&gt;

&lt;p&gt;Here is the baseline page from that corpus, unedited:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl2zri6201sv0tvabhkt7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl2zri6201sv0tvabhkt7.png" alt="The baseline page from the benchmark corpus" width="800" height="836"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look at the heading. It is a row of question marks. The script asks &lt;code&gt;cv2.putText&lt;/code&gt; to write "Оформление заказа" ("Checkout" in Russian), and &lt;code&gt;putText&lt;/code&gt; can't draw Cyrillic. So every page in my benchmark had a heading no browser would ever render, and nobody noticed. Not me, not the tests, not the engine.&lt;/p&gt;

&lt;p&gt;That should have been the first hint. Here is the loop I was actually in:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fen7w2loxcsici1adxr6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fen7w2loxcsici1adxr6n.png" alt="The self-measuring loop" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The page is drawn by OpenCV. The engine is built on OpenCV. Its thresholds were tuned on this exact corpus. Then the corpus tells me the thresholds are right. A perfect score is the expected outcome of that loop, not evidence.&lt;/p&gt;

&lt;p&gt;I didn't see it as a loop at the time. I saw it one crack at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crack 1: the score depended on which OpenCV you installed
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What I thought.&lt;/strong&gt; On one machine the engine scored 26/27 on a raster; on another, 25/27. Same code. So the engine had to be non-deterministic somewhere, and I spent two rounds of debugging inside the comparison cascade looking for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it was.&lt;/strong&gt; I finally hashed every intermediate array of the cascade on both machines. The very first array differed: the input images. The corpus was drawn on every run, and OpenCV 5 rasterizes text differently from OpenCV 4. All 54 images of the corpus differed between versions. 1.91% of the pixels on the base page, up to 222 levels in a channel. In 62% of the differing pixels, OpenCV 5 drew the stroke lighter. The text was physically thinner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdxqgyob5c8jfpbs6gvhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdxqgyob5c8jfpbs6gvhb.png" alt="The same &amp;quot;Buy now&amp;quot; drawn by OpenCV 4.14 and 5.0" width="800" height="836"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The engine was fine. The question changed under it.&lt;/p&gt;

&lt;p&gt;And there was a second layer: the "26 vs 25" comparison itself had been recorded on an older version of the engine. On the current code nobody could reproduce it. I had been chasing a number from memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What changed.&lt;/strong&gt; The corpus is now frozen on disk as PNG files, both rasters side by side as separate cases (&lt;code&gt;54ad866&lt;/code&gt;, 17 Sep). Redrawing it is a deliberate command, never a side effect of running the benchmark. And a rule I still follow: &lt;strong&gt;a number without the commit it was measured on is a memory, not a fact.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Crack 2: the engine printed a shift it never drew
&lt;/h2&gt;

&lt;p&gt;VisTest doesn't just say "these pixels differ". When it decides a difference is rendering noise, it says why: &lt;em&gt;"the baseline moved +0.30 px reproduces 100% of the changed pixels."&lt;/em&gt; That sentence is the whole point of the tool. If I call something noise, I owe you the proof.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I thought.&lt;/strong&gt; The engine shifts the baseline by a fraction of a pixel, sees if that reproduces the change, and reports the shift.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it was.&lt;/strong&gt; On OpenCV 4.x, &lt;code&gt;cv2.warpAffine&lt;/code&gt; with linear interpolation works in fixed point with 5 fractional bits. Before touching a single pixel, it rounds the shift to a 1/32 px grid. Ask for +0.30 px and you get +0.3125.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0a9ua8b4kueq8fuetxtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0a9ua8b4kueq8fuetxtc.png" alt="OpenCV 4.x rounds a sub-pixel shift to a 1/32 px grid" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the report printed +0.30, a precision that OpenCV version doesn't have. OpenCV 5 applies the shift as given, which means the same pair of PNGs was explained with different numbers on the two versions. A second note in the same file did the same thing: it reported &lt;code&gt;dx=+0.25 dy=+0.19&lt;/code&gt; while 4.x had actually drawn 8/32 and 6/32. While I was in there, I found one more: several places converted to 8-bit with &lt;code&gt;astype(np.uint8)&lt;/code&gt;, which truncates. That's a systematic bias of half a level downwards in the grey channel that every mask is computed on.&lt;/p&gt;

&lt;p&gt;An explanation that is wrong in the last digit it prints is worse than no explanation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What changed.&lt;/strong&gt; Every sub-pixel shift now goes through one module, &lt;code&gt;core/warp.py&lt;/code&gt;: bilinear interpolation written out in numpy, one rounding rule (half to even), and a test that swaps in a rounding backend to check that both code paths report what was actually drawn. After that, the detailed benchmark table is identical on OpenCV 4.14 and 5.0: all 54 pairs, every metric, not just the verdicts.&lt;/p&gt;

&lt;p&gt;Then I froze the engine's answers too, in &lt;code&gt;metrics.json&lt;/code&gt;, checked on every run. The first time it ran on another machine, it went red in the fourth decimal of a percentage. Verdicts identical. My file had stored more precision than the number has. So I measured: 25 environments, three numpy versions, two Pythons, both OpenCV majors. The version axis didn't move the numbers at all. What moved them was which SIMD kernels OpenCV picks for a Gaussian blur. Now every tolerance in that file comes with the measurement it was derived from, and the failure message prints it, so a red line can tell you whether it looks like a new machine or a changed engine (&lt;code&gt;4caabd4&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Crack 3: a test case that never existed
&lt;/h2&gt;

&lt;p&gt;After the freeze, the benchmark had two misses left. According to my plan, they were "header color" and "&lt;code&gt;Buy now&lt;/code&gt; → &lt;code&gt;Buy now!&lt;/code&gt;".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I thought.&lt;/strong&gt; Two cases, two different weaknesses. I wrote both into the brief for the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it was.&lt;/strong&gt; The first thing that step did, before changing any code, was look up both cases in the corpus manifest. "Buy now!" wasn't there. Not in the manifest, not in the generator. The closest real case was "button shrunk" ("Buy now" → "Buy"), and it passed. The name had been born in a report, I copied it into my plan, it lived there for about a month, and then it went into a task. At no step did anyone check it against the files.&lt;/p&gt;

&lt;p&gt;The two misses were one case on two rasters: "header color".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What changed.&lt;/strong&gt; The rule about commits got a sibling: &lt;strong&gt;a task that refers to a test case starts by finding that case in the manifest.&lt;/strong&gt; Case names outlive the code in reports, and they lie more convincingly than numbers. And "measure first, don't touch code" became the first step of every engine task, because it's the step that caught this.&lt;/p&gt;

&lt;h2&gt;
  
  
  The miss that was real
&lt;/h2&gt;

&lt;p&gt;The header color case is my favorite pair in the whole corpus.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2v8ymqdoq73g5jj09ht0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2v8ymqdoq73g5jj09ht0.png" alt="One number, two rulers" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The header is repainted. The color difference is ΔE00 6.7 on every one of its 57,600 pixels. For scale: around 2.3 is "just noticeable", so a person sees this immediately. pixelmatch reports &lt;strong&gt;0 differing pixels&lt;/strong&gt;. Playwright reports &lt;strong&gt;0 differing pixels&lt;/strong&gt;. And my engine passed it too.&lt;/p&gt;

&lt;p&gt;Why mine missed it: the engine wants color and structure to agree before it calls something a change. Structure is measured with SSIM, and SSIM subtracts the mean before comparing, so it's blind to a uniform shift of color by design. The only place where structure changed was the header's bottom edge, a 900×2 line, and a morphological opening removed that.&lt;/p&gt;

&lt;p&gt;The obvious fix was "the opening must never erase a component completely". I measured it first: it would have flagged 170 noise components on 12 of the 32 noise pairs. Worse, it would have made the header case fail &lt;em&gt;because of the 2-pixel edge&lt;/em&gt;, not because of the color. That's a pass for the wrong reason, which breaks the first time the layout changes. Rejected.&lt;/p&gt;

&lt;p&gt;The fix that went in is a third way past the consensus: a large, flat recolor (&lt;code&gt;1483ae4&lt;/code&gt;, 25 Sep). A connected area counts as a real change when it covers at least 1.25% of the frame and its color difference is uniform (σ/μ ≤ 0.09). Both numbers sit in the middle of a measured gap. The largest uniform noise was 0.31% of the frame (a scroll bar), the smallest header 5.2%. The most uniform noise had 0.18 unevenness, the least uniform header 0.05.&lt;/p&gt;

&lt;p&gt;One more rule from that week. I was not allowed to relabel the case. Calling it "ambiguous" would have turned 52/54 into 54/54 by a decision of the interested party, and devalued the benchmark I had just spent a week making checkable.&lt;/p&gt;

&lt;p&gt;So: 54/54. Fair and square. On my corpus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crack 4: the JPEG case passed because of swapped channels
&lt;/h2&gt;

&lt;p&gt;The same day, 25 September, the project went through a full code review, and the headline finding was one sentence: &lt;strong&gt;54/54 describes the corpus, not the engine.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first proof was the JPEG case. The corpus has a "JPEG at quality 75" pair labeled as noise, and the engine has a rule to recognize JPEG artifacts: it re-encodes the baseline at several qualities and checks if that reproduces the difference. The generator's re-encode looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;recompress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imencode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IMWRITE_JPEG_QUALITY&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imdecode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IMREAD_COLOR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OpenCV's encoder expects BGR. The generator and the engine's detector both handed it an RGB array. The same mistake on both sides, so they agreed perfectly with each other. Encode the same frame the right way, with OpenCV and the correct channel order or with Pillow on its defaults, and at quality 75 the engine fails with 4 regions. The JPEG rule had learned to recognize my generator's artifact, not JPEG.&lt;/p&gt;

&lt;p&gt;A symmetric bug is invisible to a benchmark built by the same hands. That's the whole article in one sentence.&lt;/p&gt;

&lt;p&gt;(That rule still exists. On the real-browser corpus from the next article it fires on 0 of 462 pairs, so it no longer decides anything. It's on my list.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Then I opened a real browser
&lt;/h2&gt;

&lt;p&gt;The second proof was one typical admin page in real Chromium. 21 CSS changes with labels I wrote down in advance: a link color, an underline, a border radius, a button color. Plus 4 rendering variations that really differ between machines: LCD text with sub-pixel positioning, &lt;code&gt;text-rendering&lt;/code&gt;, the page shifted by a fraction of a pixel and by 1 px.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/t2-scoreboard-en.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/t2-scoreboard-en.png" alt="One number, two rulers" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool, setting&lt;/th&gt;
&lt;th&gt;False failures (of 4)&lt;/th&gt;
&lt;th&gt;Missed (of 21)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;VisTest, default&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playwright, default&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playwright, &lt;code&gt;threshold: 0.05&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It's a probe, not a benchmark: one page, one browser, mutations I picked. It doesn't prove VisTest is worse. It proves that "0/32 vs 14/32" doesn't survive contact with a real renderer in either direction, and that my engine had blind spots the synthetic corpus could never show:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The anti-aliasing filter judged only lightness. A link going from &lt;code&gt;#2563eb&lt;/code&gt; to &lt;code&gt;#7c3aed&lt;/code&gt; passed as "strokes slightly heavier".&lt;/li&gt;
&lt;li&gt;The morphological opening that saved text erased lone thin lines. A new 1 px underline under a link passed. Playwright caught it.&lt;/li&gt;
&lt;li&gt;A button repainted up to ΔE00 ≈ 9 passed, because the new flat-recolor rule only starts at 1.25% of the frame. On a full-page screenshot the same button is even harder to see.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Five other rendering variations (a restart, two hinting modes, GPU rasterization, headless shell vs full Chromium) gave &lt;strong&gt;0 differing pixels&lt;/strong&gt;. On a pinned environment, there was no noise to filter at all. My engine had been built to explain noise that a real browser, set up properly, mostly doesn't produce, and it was missing changes that a real browser does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed in how I work
&lt;/h2&gt;

&lt;p&gt;The code fixes are in the repo. These are the habits that came out of that month, and they matter more:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A ruler drawn by the hand that set the thresholds measures self-persuasion.&lt;/strong&gt; The benchmark has to be produced by something that doesn't know about the engine. For a screenshot tool, that means a real browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every number gets a date and a commit.&lt;/strong&gt; Without one, it's a memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every case name gets checked against the files&lt;/strong&gt; before anyone works on it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Labels don't move to improve a score.&lt;/strong&gt; If one ever changes, the changelog says the number went up because of relabeling, not because of the engine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Determinism is tested, not assumed.&lt;/strong&gt; The engine's answers to the corpus are frozen and replayed on every merge, with measured tolerances.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explanations must be exact.&lt;/strong&gt; If the tool says "moved by +0.30 px", it moved by exactly that.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where it is now
&lt;/h2&gt;

&lt;p&gt;VisTest is on PyPI and on GitHub under Apache-2.0. It's one function in your pytest tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="s2"&gt;"vistest[browser]"&lt;/span&gt;
playwright &lt;span class="nb"&gt;install &lt;/span&gt;chromium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;vistest&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;expect_screenshot&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_home&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;expect_screenshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;home.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a check fails, it doesn't print a percentage. It tells you what changed, &lt;em&gt;"fill: #3478f6 → #1d4ed8, color difference 14.5"&lt;/em&gt;, and shows it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65730cizbmqa8bhvh8r8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65730cizbmqa8bhvh8r8.png" alt="A failed check in VisTest: the changed button framed on the dimmed page" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The engine you install today isn't the one from this article. It was rebuilt on top of the corpus from a real browser, and the claim I'm willing to make now is narrower than "54/54": &lt;strong&gt;on the same renderer, it catches changes Playwright misses, with no more false failures.&lt;/strong&gt; How I built that corpus, and how badly the engine lost on it at first, is the next article.&lt;/p&gt;

&lt;p&gt;If you work with screenshot tests, I'd love for you to try it on your own failures. There's a command for exactly that: &lt;code&gt;vistest bench &amp;lt;folder&amp;gt;&lt;/code&gt; takes your existing baseline/actual pairs, including Playwright's layout, and shows where VisTest and Playwright disagree. Tell me where it's wrong.&lt;/p&gt;

&lt;p&gt;⭐ &lt;strong&gt;&lt;a href="https://github.com/marshlw/vistest" rel="noopener noreferrer"&gt;github.com/marshlw/vistest&lt;/a&gt;&lt;/strong&gt;: code, the frozen corpus, the benchmark scripts and the full development journal, mistakes included.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Next: "A corpus from a real browser, and a cold shower."&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>playwright</category>
      <category>testing</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Playwright for Python has no toHaveScreenshot, so I wrote a visual testing library</title>
      <dc:creator>Kirill</dc:creator>
      <pubDate>Wed, 04 Nov 2026 12:17:57 +0000</pubDate>
      <link>https://dev.to/marshlw/playwright-for-python-has-no-tohavescreenshot-so-i-wrote-a-visual-testing-library-1fe5</link>
      <guid>https://dev.to/marshlw/playwright-for-python-has-no-tohavescreenshot-so-i-wrote-a-visual-testing-library-1fe5</guid>
      <description>&lt;p&gt;I write test automation in Python: pytest, Playwright, CI. And from project to project I keep seeing the same picture. API tests, UI tests, reports: there is a good tool for all of it. But the moment you need to check how a page &lt;em&gt;looks&lt;/em&gt;, the workarounds begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was missing
&lt;/h2&gt;

&lt;p&gt;Playwright for JavaScript has &lt;code&gt;toHaveScreenshot()&lt;/code&gt;: one line, and the test compares the page with a baseline. Playwright for Python has nothing like it. When I started, the options were thin: a couple of small plugins on top of pixel-by-pixel comparison, or a home-grown wrapper that every team writes from scratch.&lt;/p&gt;

&lt;p&gt;And pixel-by-pixel comparison breaks in two ways.&lt;/p&gt;

&lt;p&gt;The first: the test goes red although the page did not change. A font rendered half a pixel differently, CI ran on another machine. The team puts up with it for a week, then someone adds automatic baseline updates to the pipeline. Visual tests still exist on paper, but in practice they are switched off.&lt;/p&gt;

&lt;p&gt;The second: to stop the red, people set a threshold like "98% similar". And the test stops seeing small things. But a UI breaks exactly in small things: the wrong checkbox state, the wrong button colour, a border off by one pixel.&lt;/p&gt;

&lt;p&gt;I have seen this first-hand. In one project a screenshot suite had been green for six months. It compared the whole frame with a 0.98 threshold. And all that time it was missing a real bug. More on that below.&lt;/p&gt;

&lt;p&gt;What I wanted was simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pip install&lt;/code&gt;, one function in the test, baselines in the repository;&lt;/li&gt;
&lt;li&gt;the test does not fail when the page is merely redrawn a little differently;&lt;/li&gt;
&lt;li&gt;the test does fail on a small real change;&lt;/li&gt;
&lt;li&gt;and most importantly, it says in words what changed: "button recoloured", "block moved by one pixel", not "3.2% mismatch".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is how VisTest started.&lt;/p&gt;

&lt;h2&gt;
  
  
  First I built the wrong thing
&lt;/h2&gt;

&lt;p&gt;Let me admit it right away: the first version was not a library but a platform. A server, a review web UI, run history, a mouse recorder for tests, single sign-on. I thought the product was all of that, and image comparison was a detail inside that already worked.&lt;/p&gt;

&lt;p&gt;Then I counted. The comparison itself was about a tenth of the code. The other nine tenths served an engine I had never tested on real screenshots, only on pictures drawn by my own code.&lt;/p&gt;

&lt;p&gt;I realised it when I tried to plug the tool into someone else's project. You cannot pip-install a platform into someone else's tests. So VisTest narrowed down to what I should have started with: a library and a pytest plugin. The team server did not go away, but it became a separate product for later.&lt;/p&gt;

&lt;h2&gt;
  
  
  First contact with a real project
&lt;/h2&gt;

&lt;p&gt;The pilot was an internal Playwright project with 11 screenshot tests. There was one piece of good news, and it mattered: adoption came down to replacing a single wrapper method. The tests themselves did not change by a single line.&lt;/p&gt;

&lt;p&gt;Then, within the first few minutes, we found more problems than in the whole development so far. The three most telling ones:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One difference killed the whole run.&lt;/strong&gt; The fifth test found a real mismatch, and pytest crashed entirely with an internal error. The other six tests never ran, and there was no report. A tool meant to help find regressions buried the run at the exact moment it found one. Now the rule is simple: a configuration error is loud and immediate; a failure in an optional part is a warning, and the tests carry on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The numbers in the message did not add up.&lt;/strong&gt; "1.44% of the frame changed", while the regions it named added up to dozens of times less. A person reading a CI log cannot reconcile numbers like that, and stops trusting both. Now the area is broken into parts that always add up to the total.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The engine erased text.&lt;/strong&gt; To remove noise, the change mask was cleaned with a morphological filter, and along with the noise it threw away everything thinner than five pixels. Which is almost all text. On one pair of images, 97% of a real change disappeared before the engine even started looking at it. I changed the order of operations and gave noise its own explanations. Now every discarded difference is labelled with the rule that discarded it.&lt;/p&gt;

&lt;p&gt;None of these bugs would have been caught by my own tests, and by then I had more than a thousand of them. Your own tests check what you thought of. Someone else's project checks what nobody thought of.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it was all for
&lt;/h2&gt;

&lt;p&gt;On the second run, VisTest found a real bug in that very suite that had been green for six months. The state of a filter panel was carrying over from one page to another when it should not have. The difference sat on 35-pixel checkboxes. A whole-frame comparison with a 0.98 threshold could never see it: 35 pixels on a full-screen screenshot barely move the overall "similarity".&lt;/p&gt;

&lt;p&gt;One finding across eleven tests is not statistics, and I do not conclude from it that "VisTest is better". But it shows the problem is real: a whole class of changes slips past an ordinary check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the project is now
&lt;/h2&gt;

&lt;p&gt;VisTest is on PyPI as an alpha, open source under the Apache-2.0 licence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="s2"&gt;"vistest[browser]"&lt;/span&gt;
playwright &lt;span class="nb"&gt;install &lt;/span&gt;chromium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;vistest&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;expect_screenshot&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_landing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;expect_screenshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;landing.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run is red: there is no baseline yet. &lt;code&gt;pytest --vistest-update&lt;/code&gt; writes the baselines; you look at them and commit them. From then on the test compares, and if something changed, it explains what and where.&lt;/p&gt;

&lt;p&gt;There are no comparison numbers against other tools here, on purpose. The next posts are about exactly that: how I measured my engine, how I fooled myself with nice-looking results, and how I then lost to Playwright on real browser screenshots. That story is more useful than any victory table.&lt;/p&gt;

&lt;p&gt;If you write tests in Python and have also been looking for a &lt;code&gt;toHaveScreenshot&lt;/code&gt; replacement, give VisTest a try and tell me what broke. Someone else's project, as it turned out, is the best test.&lt;/p&gt;

&lt;p&gt;Next in the series…&lt;/p&gt;

&lt;p&gt;Repository: &lt;a href="https://github.com/marshlw/vistest" rel="noopener noreferrer"&gt;github.com/marshlw/vistest&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>playwright</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
