How to compare two images

Hi All,
I need to compare two screenshots of SUT.
First I capture the screenshot 1 for application 1 after made some changes again I need to capture the screenshot 2.
Now I have to compare the two screenshots.
If data of screenshots same then it will log correct data otherwise, logerror like data has been modified.

Please suggest me.

Here’s your script-

If ImageFound(4.0, “Image1”)
Log “Image 1 found”
LogWarning “Image1 not found, please check”
end if

wait 10.0

If ImageFound(5.0, “Image2”)
Log “Image 2 found”
LogWarning “Image 2 not found, Please check”
end if

If “Image1” = “Image2”
Log “Images found same - no further changes observed”
LogError “Images not identical”
end if

You also need to make sure to modify Wait Time based on screen navigations. Also have a look below link which details using expressions in EggPlant -

Hi ,

I am capturing the image while running the script.
I came to know it is not possible to compare the images

That’s correct. You cannot manually capture images while running the script.

Even you cannot edit the script while running the tool. You can only able to edit the script in main window but not in running window while execution in process.

There are at least two ways to compare two screenshots of the SUT. The first is to capture the original image and then search for it again later, possibly using a searchRectangle to look only in the place where you expect it to appear. If it is found then you can log success.

The other approach is to capture the same area of the screen at two different times into two image files and compare those files. Here’s how it would look:

set areaOfInterest to (100,100,300,300) -- the area of the screen to compare
captureScreen "/tmp/originalImage", areaOfInterest

-- do some other processing

captureScreen "/tmp/laterImage", areaOfInterest -- capture the same area again

if file "/tmp/originalImage.tiff" as data is equal to file "/tmp/laterImage.tiff" as data then
    logSuccess "The images are the same"
    logFailure "The images are different"
end if

Note that if you’re running on Windows or Linux the images will be captured as .png files not .tiff, and on Windows you’ll need to store them in a different directory, not /tmp. But if you’re careful to get the image file names correct, this approach should work. It’s also important that you compare the files “as data” so SenseTalk won’t try to convert them to text strings which would give unreliable results when comparing binary data.

Thanks for this solution. this is working fine for me.
Now, I want to compare with 3 screenshots.

I have one defaults image , image x , image y

first I have to compare with default image with image x
if those are same log “sucess” not same "logerror “fail”

second condition compare with imagex and imagey

second condition is working fine as you given example in last forum.

here, I am trying to execute like this but I am getting error please verify and send me correct code

if file "/tmp/default.tiff" as data is equal to file "/tmp/imagex.tiff" as data then 
    logerror "The images are not  same" 
else if file "/tmp/x.tiff" as data is equal to file "/tmp/y.tiff" as data then
log " the images are same"
    logFailure "The images are different" 
end if

I think you will want to use “LogError” instead of “LogFailure” towards the end. The LogError command will cause the script to log as a failure if it is executed.

If this does not resolve your problem, can you tell us what error message it is that you are seeing?