Fuzzy screenshot comparison with Selenium

前端 未结 4 2101
我在风中等你
我在风中等你 2021-02-05 20:22

I\'m using Selenium to automate webpage functional testing. It\'s important for us to do a pixel-by-pixel comparison when we roll out new code, so we\'re using Selenium to take

4条回答
  •  不思量自难忘°
    2021-02-05 21:01

    So I ended up going with the ImageMagick command-line tool (because why re-invent image comparison). The "Peak Absolute Error" metric of the "compare" tool tells you how much you have to fuzz pixels before two images are identical. This seems to work well... for an image with slight graphical distortions, there might be a lot of pixels that don't match, but slight fuzzing is enough to make them match; but for two images that are actually different, even though most pixels might match, the ones that don't tend to be very different. Right now I'm checking for a PAE of less than 15% to see if the images should be counted as identical. Command line I'm using is:

     compare -metric PAE  original.png new.png comparison.png
    

    Documentation on ImageMagick's compare tool is here: http://www.imagemagick.org/script/compare.php

提交回复
热议问题