Compare Screenshotes

I have two image screenshots. One image is rectangle part of of another screenshot. I need to verify the complete screenshot contain the part of another image.
Please let me know which api I need to use.

Thanks in advance.

Hi Basil,

Have you already looked at the CompareScreens command and function? Results and Reporting | EPF Docs

If you could get by with just looking at part of the screen, taking a picture of it, then seeing if it changed later, something like this might work:

Params TopLeftX, TopLeftY, BottomRightX, BottomRightY
Log "Checking to see if something changed in a specified area."
set the searchRectangle to (TopLeftX, TopLeftY, BottomRightX, BottomRightY)
CaptureScreen Name: "StartingState", Rectangle: [TopLeftX, TopLeftY, BottomRightX, BottomRightY]
put the result into refImage
Wait 5
If not imageFound(refImage) then
	logSuccess "Screen section appears to have changed."
	logError "Screen section does not appear to have changed."
End If
set the searchRectangle to fullscreen

Thank you for the reply @DSDeep and @DaveHester ,

Here what I need I don’t need to compare image with SUT screen,
I’m already having Image database then I need to capture image multiple times in SUT with 2 second period of time, each time a icon will change in SUT,
So later I need to verify captured images with image database which are same or not.

And I believe if I verify image instead of capture image in each period of time it will take more than 2 second, I have already tested it, here each of 2 second icon will change, that’s why I’m capturing Image at that time.

In that case, I would capture just the images you need to see change, and do something like:

waitfor 4, “ImageToSee1”
waitfor 4, “ImageToSee2”
waitfor 4, “ImageToSee3”


This way you can ‘see’ each images as it appears, and verify all the appropriate changes in order.

If you still need to capture images, you can just add those screen capture commands between the waitfors.

Hi @DSDeep ,
Can you please tell me for running each script in eggplant I need to do three steps I believe, one is start the session then run script finally end the session.
For each of these process it will take 3.3s, 1.2s and 0.15 second respectively.
So for single verification it taking around 5 second. Is there any way I can optimize the time !!?
If I want to run each verification individually it should be verify within 2 second, because the icons in SUT only appear for the 2 second.

Also one more help I needed, Is there any way we can load an Image in SUT !!?

And thank you for your valuable help.

Hi Basil,
In order to compare images within Eggplant Function, you will need to use SUT functionality. SenseTalk has the ability to compare text, Excel, and ODBC-compliant files without using a SUT, but it does not have the ability to compare portions of image files without using a SUT. Fortunately, you can use the Connect command to use a stored image itself as the SUT. That code looks like this:
connect "/Users/bob/Documents/EggplantSuites/Test.suite/Results/bug2029/20130903_134649.212/Screen_Error.tiff", type:"screenshot" // Connects to a screenshot saved in the suite
You can find information on the Connect Command here: SUT Information and Control | EPF Docs
Taken together, my code might look like this:

//Assumes that images are stored within two folders within the Resource folder of the suite
//Assumes that the naming convention of the partial screenshots and the complete screenshots is the same
//If images are not stored in the Resources folder, modify the file path below
//If the image names are not the same in the partial folder as the complete folder, they must at least be in the same order alphabetically
put the files of ResourcePath("MyPartialScreenshotsFolder") into MyPartialScreenshotsList
put the files of ResourcePath("MyCompleteScreenshotsFolder") into MyCompleteScreenshotsList
Repeat with each item MyScreenshotConnection of MyCompleteScreenshotsList
	Connect ResourcePath(MyScreenshotConnection),type:screenshot
	Put "The result of comparing image" && MyScreenshotConnection && "is" && ImageFound(image:ResourcePath("MyPartialScreenshotsFolder"&slash&(item repeatindex() of MyPartialScreenshotsList)),WaitFor:0) -- returns true or false
End Repeat

When I ran the code above, it took less than 1 second per image.

Hope this helps,

Hi @DaveHester
I really appreciate your valuable help,

So here when you ran the code and it took less than 1 second, is it without start xmlrpc session !!?

In my case I’m running eggplant functional in drive mode, because an external application is invoking eggplant.
So every time when I run a script I need to start session that itself taking more than 2 second.

Hi @basil,
The key to quicker runtimes will be to check multiple images within a single test. For example, my script compared 10 images and had a total runtime of just 9 seconds. Even if I were running the test via an external process that took 3 seconds to start and 3 seconds to stop, my total runtime would be 15 seconds or 1.5 seconds per image. If your business case is to test one image per run, you will not achieve your goal of 2 seconds of runtime per image.
Hope this helps,

Thank you @DSDeep for clarification.