capybara-screenshot-diff icon indicating copy to clipboard operation
capybara-screenshot-diff copied to clipboard

Unexpected file diffs when fail_on_difference is true

Open Intrepidd opened this issue 5 months ago • 7 comments

When fail_on_difference is set to true, running the specs will pass but screenshots files will be changed (I see them as modified with git status), with no visible diffs in the heatmap

If I set it to false, the screenshots will not be changed.

This didn't happen before, I think it is now happening since I changed my screen (from 1080p to 1444p), could it explain this behavior ?

Intrepidd avatar Aug 18 '25 09:08 Intrepidd

@Intrepidd yep, the problem is that when you change the screenshot size, you need to re-generate new screenshots with the new sizes first. We have not added auto-rescaling yet.

pftg avatar Aug 18 '25 13:08 pftg

The screenshot size did not change (in the capybara config), just the screen resolution. The produced screenshots are still the same size

Intrepidd avatar Aug 18 '25 13:08 Intrepidd

Oh, I got it. Sorry for the confusion. fail_on_difference has been added to regenerate all screenshots without failing tests: https://github.com/snap-diff/snap_diff-capybara/pull/109 to ensure that they are up to date.

If I set it to false, the screenshots will not be changed.

We do not store new versions; we just reuse previous screenshots. When your tests have been passed because of some enabled filters, you do not need to have a diff report for them.

pftg avatar Aug 18 '25 13:08 pftg

My understanding is that it should not overwrite screenshots if there is no diff, which I believe (but I can be wrong) was the case before for me. Do I make sense ?

Intrepidd avatar Aug 18 '25 14:08 Intrepidd

@Intrepidd, comparing screenshots is expensive, so we take screenshots and override the latest version by default. If we run verification, we will rollback the action on the difference, but if we do not find a difference, we will not rollback.

pftg avatar Aug 23 '25 16:08 pftg

gotcha, thanks for the precision !

Would you be interested in a way to configure the gem so it matches the behaviour I was expecting :

  • Don't fail in case of mismatch
  • But don't take screenshot / rollback screenshot if it matches

Intrepidd avatar Aug 25 '25 08:08 Intrepidd

gotcha, thanks for the precision !

Would you be interested in a way to configure the gem so it matches the behaviour I was expecting :

  • Don't fail in case of mismatch
  • But don't take screenshot / rollback screenshot if it matches

@donv what do you think?

pftg avatar Aug 25 '25 08:08 pftg