Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is there a way to ignore small difference between snapshots? #7346

Closed
DZakh opened this issue Jun 28, 2021 · 7 comments
Closed

[Question] Is there a way to ignore small difference between snapshots? #7346

DZakh opened this issue Jun 28, 2021 · 7 comments

Comments

@DZakh
Copy link
Contributor

DZakh commented Jun 28, 2021

I have an expected image snapshot and the only different thing comparing to an actual one is the text cursor. Because of this my test suit fails. I've tryed to increase the threshold option to the max but it didn't work. Do I understand it correctly, that threshold is only related to how accurate different pixels are found, not to the percentage of omitted overlapping pixels.

const count = pixelmatch_1.default(expected.data, actual.data, diff.data, expected.width, expected.height, { threshold: 0.2, ...options });

In my case the variable count from the source always returns 16 and threshold doesn't change anything.

In my opinion it should work something like this:

const count = // get the number of different pixels ...
const pass = count / (width * height) < threshold

Is there a way to ignore small difference between snapshots?

@pavelfeldman
Copy link
Member

I wonder if you would benefit from us hiding the cursor when capturing the screenshot instead.

@DZakh
Copy link
Contributor Author

DZakh commented Jun 28, 2021

I wonder if you would benefit from us hiding the cursor when capturing the screenshot instead.

No, I think it's a partial soltion, that may even harm other people.
Also, for instance I have other cases not related to the text cursor in my app, these are the app version that changes every commit and a lot of dates from server. Of course I can twik my app logic a little bit to always show the same result during tests, but I find the ability to set some kind of ignorance level when I match snapshots more appealing.
By ignorance level I mean that I can set some percentage, and if the number of different pixels devided to the number of all pixels is less than ignorance level then consider the test as successful.

@dgozman
Copy link
Contributor

dgozman commented Jul 7, 2021

@DZakh This is an interesting idea, but we have to gather more feedback before changing how snapshot matching works.

Meanwhile, you can also capture an element screenshot to avoid the area with the ever-changing version, or anything else that is not stable. Would that work for you?

@sergioariveros
Copy link

This is also a feature that will help us, as we need to ignore some parts in our screenshoot that always are moving and making the comparison fails

@aslushnikov
Copy link
Collaborator

I have an expected image snapshot and the only different thing comparing to an actual one is the text cursor.

@DZakh as of 547a328 we now hide blinking cursor when making the screenshot. This is already available on @playwright/test@next and will be released in the upcoming @playwright/[email protected].

Do I understand it correctly, that threshold is only related to how accurate different pixels are found, not to the percentage of omitted overlapping pixels.

You understand correctly, and that's pretty unfortunate. We have another tracking bug for this: #10219

This is also a feature that will help us, as we need to ignore some parts in our screenshoot that always are moving and making the comparison fails

@sergioariveros this is coming via #11913

I'll close this in favor of mentioned separate issues.

@ritz078
Copy link

ritz078 commented Feb 18, 2022

@aslushnikov It looks like the cursor is not hidden on firefox (Linux). I had to add color: transparent to hide them.

@aslushnikov
Copy link
Collaborator

@ritz078 interesting! Could you please share a repro? (Preferrably, in a new issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants