fix(playwright): recognize modern screenshot comparison errors - #808
Open
dimazollo wants to merge 3 commits into
Open
fix(playwright): recognize modern screenshot comparison errors#808dimazollo wants to merge 3 commits into
dimazollo wants to merge 3 commits into
Conversation
sipayRT
requested changes
Sep 8, 2026
| if (/snapshot .*doesn't exist/.test(message) && message.includes('.png')) { | ||
| result.name = ErrorName.NO_REF_IMAGE; | ||
| } else if (message.includes('Screenshot comparison failed')) { | ||
| } else if (this._testResult.errors.every(error => this._isScreenshotComparisonError(error))) { |
Member
There was a problem hiding this comment.
why is it not enough to just switch to 2 error options? for example, /Screenshot comparison failed|expect\(.*\)\.toHaveScreenshot\(expected\)failed/
Author
There was a problem hiding this comment.
Playwright uses the same header when it cannot take a screenshot. So I also check that expected, actual, and diff images are attached.
I'll keep toHaveScreenshot support with this check and remove the mixed-error changes from this PR.
| return true; | ||
| } | ||
|
|
||
| if (!/^(?:Error: )?expect\((?:page|locator|Buffer)\)\.(?:toHaveScreenshot|toMatchSnapshot)\(expected\)(?: failed)?$/.test(header)) { |
Member
There was a problem hiding this comment.
toMatchSnapshot should be used for non-image comparison, so we don't need this part here
Author
There was a problem hiding this comment.
It can compare images too, but I agree that we don't need it for this fix. I'll remove it from this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Playwright 1.59.1 reports screenshot mismatches as:
The adapter only recognizes
Screenshot comparison failed, so it marks these as general errors even when expected/actual/diff images are attached. Accept can then leave a stale error instead of resolving the visual failure.This adds support for the newer page/locator
toHaveScreenshotheader. Playwright uses the same header when it cannot take a screenshot, so the adapter also checks for matching expected/actual/diff attachments. The oldScreenshot comparison failedhandling stays unchanged.Only the adapter and its unit tests change.
toMatchSnapshot, changes to legacy mixed-error handling, and platform handling are outside this PR.Reproduction
With Playwright 1.59.1 and
html-reporter/playwright:Before:
error/Error. After:fail/ImageDiffError.Tests
npm testpasses on Node 20.19.6: lint, Node and jsdom unit tests, and type checks.The full GUI e2e suite and interactive Accept/Undo weren't rerun for this isolated fix.
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en.