Handling/Reporting on Object Location Differences

Robot code snippets will be placed here for perusal & download by the T-Plan Community.
Post Reply
Dave
Site Admin
Site Admin
Posts: 21
Joined: Wed Oct 29, 2003 5:26 pm
Contact:

Handling/Reporting on Object Location Differences

Post by Dave » Wed Nov 02, 2011 5:19 pm

This example shows one way that Robot can search for an image and report if it's location differs from its original.

The script follows these steps:
1. Perform a comparison of image/button against the displayed screen
2. If the image is not found at all Exit
3. Check if the located image coordinates differ from the original
4. If coordinates differ record a step indicating this along with x/y difference values
5. Click the located image

Code: Select all

===========================================================
// Perform comparison of image/button against the displayed screen:
Waitfor "match" template="<imagename>.png" method="search" timeout="10s"
if ({_EXIT_CODE} > 0) {
// If image is not found at all Exit.
  Exit 1
// Check if the image coordinates differ from the original.
} else if ("{_COMPARETO_SOURCE_X}" != "{_SEARCH_X}" || "{_COMPARETO_SOURCE_Y}" != "{_SEARCH_Y}") {
// Create variables to evaluate the coordinate differences.
  Eval LocationX="{_SEARCH_X}-{_COMPARETO_SOURCE_X}"
  Eval LocationY="{_SEARCH_Y}-{_COMPARETO_SOURCE_Y}"
// Record a step indicating that the location differed along with x/y difference values.
Step "Image was found but in a different location. The difference was {LocationX} pixels horizontally and {LocationY} pixels vertically."
}
// Click the located image.
Mouse click to=x:{_COMPARETO_CLICK_X},y:{_COMPARETO_CLICK_Y}
===========================================================
As I mention this is one example with many possible variations, such as the text within the reported step can be altered as desired as can the exit code and behaviour upon a failed image search. It can also be further enhanced, for example, to take a screenshot of the new location etc.

Please be aware that the comparison against the original coordinates of an image can only occur for templates that are generated within Robot. The reason being that Robot stores the original image data in a properties file which obviously will not be present if using image templates generated by third party sources.

For any assistance please email Support@T-Plan.com.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest