pazone / ashot

WebDriver Screenshot utility. Take screenshots, crop, prettify, compare
Other
636 stars 157 forks source link

Image comparison is failing for same image in same navigator due to Pixels difference #157

Open aymen3redlean opened 5 years ago

aymen3redlean commented 5 years ago

Hello,

we use ashot in selenium project to compare two images in a specific test case.

In same case, the image are the same but image comparison fails due to Mismatched pixels

Is the any way to fix this? Or to reduce sensibility in image comparison?

valfirst commented 5 years ago

@aymen3redlean could you please provide more details? what is actual reason of the mismatch in your case?

aymen3redlean commented 5 years ago

Hello, According to the comparison, there are some pixels were be shifted from their original positions. Is there a way to ignored this case and say that the two images are same?

valfirst commented 5 years ago

@aymen3redlean do you have any idea why pixels are shifted? also could you please post the code you use to compare images?

aymen3redlean commented 5 years ago

The screenshots are the same but taken in different time which can be the origin of the shift.

Please find in below the comparison code:

try {
            ImageDiffer imgDiff = new ImageDiffer();
            ImageDiff imageResult = imgDiff.makeDiff(
                    ImageIO.read(new File(RunFolderPath + "\\" + imageTabName + "_1_" + level + ".png")),
                    ImageIO.read(new File(RunFolderPath + "\\" + imageTabName + "_2_" + level + ".png")));

            if (imageResult.hasDiff()) {
                BufferedImage y = imageResult.getMarkedImage();

                ImageIO.write(y, "PNG", new File(imageTabName + "_diff.png"));

            }

        } catch (Exception e) {

            new Exception();
        }
valfirst commented 5 years ago

@aymen3redlean you can try changing the value of diff size trigger:

PointsMarkupPolicy diffMarkupPolicy = new PointsMarkupPolicy();
diffMarkupPolicy.setDiffSizeTrigger(<put_your_value_here>);
ImageDiffer imgDiff = new ImageDiffer().withDiffMarkupPolicy(diffMarkupPolicy);
...
varshasaha commented 4 years ago

I am facing the same issue, how should we use setDiffSizeTrigger, is there any threshold to comparison we can give, like fail if 90% of image doesn't match, right now it fails even if the text shifts a bit

clickOnSellerDetails_diffImage