Image and OCR Searches
These commands and functions execute image or optical character recognition (OCR) searches on the system under test (SUT).
You can further control the search behavior of the image and OCR search commands and functions below by using the ImageSearchCount, the ImageSearchDelay, and the ImageSearchTime global properties.
EveryImageLocation
Function
Behavior: Searches the SUT for all occurrences of the given images or text (OCR); returns a list of the hot spot coordinates for every occurrence of the images, or a list for the center of the text string when using OCR. Coordinates are listed in the order in which they are found, where images and text closest to the top left corner of the SUT are found first. If no image or text (OCR) is found, EveryImageLocation
returns an empty list.
Parameters: One or more Image References or properties, or Text Properties (for OCR).
Syntax:
EveryImageLocation( imageOrTextReference )
Returns: The coordinates of every instance of the given image or images. For example:
((288,325),(288,356),(288,387),(288,448))
Example:
Including the ImageName
property is required when passing additional image search properties as in this example.
log EveryImageLocation(ImageName:"CheckBoxes",scale:[1,.5]) // Logs a list of hot spot coordinates for every occurrence of the image found at both the original size and half scale. Note the use of the ImageName property when including additional properties for the image search.
Example:
click the penultimate item of EveryImageLocation(text:"AddressField") // Clicks the penultimate (second to last) item in the list of occurrences of the text (OCR).
Example:
set the RemoteWorkInterval to .1 // Shortens the RemoteWorkInterval (default=.7) to decrease the pause between actions that Eggplant Functional sends to your SUT. This change allows the series of clicks to execute much faster.
repeat with EveryImageLocation("RadioButton") // Iterates through each occurrence of the image found with everyImageLocation().
click it // Using the it variable, clicks the current occurrence the repeat loop is operating on.
end repeat
set the RemoteWorkInterval to .7
Example:
// The following example provides an alternate syntax for the previous example.
repeat with each item of EveryImageLocation("RadioButton")
click it // Using the it variable, clicks the current occurrence the repeat loop is operating on.
end repeat
When you call the EveryImageLocation
function, you can immediately call the result
to return ImageInfo
for every image represented in EveryImageLocation
.
Example:
put EveryImageLocation("GreenSaveButton","BlueSaveButton","RedSaveButton") // Returns a list of hot spot coordinates for every occurrence of the image.
put the result // Returns imageInfo for every image represented in EveryImageLocation.
EveryImageRectangle
Function
Behavior: Searches the SUT for all occurrences of the given images or text (OCR); returns a list of the rectangle coordinates for every occurrence of the images or text (OCR). Coordinates are listed in the order in which they are found, where images and text closest to the top left corner of the SUT are found first. If no image or text (OCR) is found, EveryImageRectangle
returns an empty list.
Parameters: One or more Image References or properties, or Text Properties (for OCR).
Syntax:
EveryImageRectangle( imageOrTextReference )
Returns: The rectangle coordinates of every instance of the given image or images.
Example:
put EveryImageRectangle("TotalAmountLabel", "ItemizedAmountLabel") // Returns a list of rectangle coordinates for every occurrence of the images.
Example:
assert that the number of items in EveryImageRectangle(ImageName:"CheckBoxes",searchRectangle:["SelectOptionsUpperLeft","SelectOptionsLowerRight"]) is 4 // Asserts whether the number of occurrences of the image is equal to the expected number, 4. Example output: AssertionFailed (assertion: the number of items in EveryImageRectangle(ImageName:"ImageName") is 4; actually: 5 IS NOT equal to 4)
Example:
Set StatusRectangles to EveryImageRectangle(text:"StatusLabel") // Stores the return of EveryImageRectangle in a variable called StatusRectangles.
Log "There are"&&the number of items of StatusRectangles&&"statuses to check." // Uses concatenation to join two strings with the number of occurrences in the list stored in StatusRectangles, and logs the output.
repeat with each Rectangle of StatusRectangles // Iterates on each item in the list using the variable name Rectangle.
Set StatusIndicatorLocation to the TopRight of Rectangle plus (15,0) // Makes a coordinate adjustment 15 pixels to the right of the top right corner of the current occurrence and stores it in variable StatusIndicatorLocation.
If ColorAtLocation(StatusIndicatorLocation) is "59,170,43" then Log "The status is green." // Uses the ColorAtLocation() function to find the RGB value at StatusIndicatorLocation, then compares it to the expected RGB value, 59,170,43.
end repeat
When you call the EveryImageRectangle
function, you can immediately call the result
to return ImageInfo
for every image represented in EveryImageRectangle
.
Example:
put EveryImageRectangle("GreenSaveButton","BlueSaveButton","RedSaveButton") // Returns a list of rectangle coordinates for every occurrence of these images.
put the result // Returns imageInfo for every image represented in EveryImageRectangle.