selenium-shutterbug icon indicating copy to clipboard operation
selenium-shutterbug copied to clipboard

Display image filename/filepath in exceptions

Open sergiu-mezei-aera opened this issue 2 years ago • 2 comments

Hi guys,

We're using shutterbug to do multiple image comparisons inside a test method and we're using Allure reports for the reporting part. I would like to suggest an improvement: displaying the image filename/filepath inside the exceptions thrown rather than just the "image1"/"image2" hardcoded strings or at least any image path information (like the resulting diff image path). This would help us to easily debug and fix tests because we know which images are affected.

For example: We get an exception like this: Images dimensions mismatch: image1 - 300x753; image2 - 300x754 com.assertthat.selenium_shutterbug.utils.image.UnableToCompareImagesException: Images dimensions mismatch: image1 - 300x753; image2 - 300x754 at com.assertthat.selenium_shutterbug.utils.image.ImageProcessor.imagesAreEqualsWithDiff(ImageProcessor.java:140) at com.assertthat.selenium_shutterbug.core.Snapshot.equalsWithDiff(Snapshot.java:325) at utils.ImageCompare.compareWebElement(ImageCompare.java:133) at ui_tests.ui_builder_tests.TableComponentTest6.goToNextNodeRowSelectionTrueTest(TableComponentTest6.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Thanks in advance!

sergiu-mezei-aera avatar Oct 12 '22 06:10 sergiu-mezei-aera

Hi @sergiu-mezei-aera ,

Could you please share the snippet of code which you use to do the comparison? Do you read both images from the disk first?

glibas avatar Oct 13 '22 19:10 glibas

Hi @glibas,

I read the expected image (BufferedImage) from the disk and the image we compare with is a UI capture (snapshot).

saveSnapshot(actual, imageName + "-actual", actualScreenShotFolder);

boolean result = actual.equalsWithDiff(expected, diffFolder + imageName, deviation);

The exception comes from the equalsWithDiff() method, but we need more info of the image1/2 names to be clearer for debugging.

sergiu-mezei-aera avatar Oct 14 '22 08:10 sergiu-mezei-aera