Image and OCR Searches
These commands and functions search for elements on the system under test (SUT) using one of Eggplant Functional (EPF)'s search methods:
- Find by Description: Search for elements on the SUT screen by providing a description of the element to an LLM (Large Language Model).
- Image-Based Testing: Capture images of elements on the SUT screen, which are then referenced from SenseTalk scripts in order to search for and interact with those elements.
- OCR: Use optical character recognition to search for or read text on the screen of the SUT.
You can further control the search behavior of the commands and functions below by using global properties:
EveryImageLocation Function
You can use AI searches with this function.
For more information, see Find by Description.
Behavior: Searches the SUT for all occurrences of the elements described (Find by Description), images specified (captured image search), or text strings (OCR).
Returns a list of the hot spot coordinates for every occurrence of the elements or 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 elements, images, and text closest to the top left corner of the SUT are found first. If no element, image, or text is found, EveryImageLocation returns an empty list.
Parameters: One or more descriptions (for Find by Description searches), one or more Image References (for captured image searches), or one or more Text Properties (for OCR searches).
Syntax:
EveryImageLocation( imageOrTextReference )
Returns: The rectangle coordinates of every instance of the described element(s) (Find by Description), specified captured image(s), or text (OCR). For example:
[[288,325],[288,356],[288,387],[288,448]]
Example: Using a Find by Description Search:
Use an AI-powered Find by Description search to locate every instance of the user account icon on the SUT screen, by providing a description property:
log everyimagelocation(description:"the Eggplant Functional icon") -- Logs a list of hot spot coordinates for every occurrence of the element found.
Example: Using a Captured Image Search:
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: Using an OCR Text Search:
To find text using OCR, provide a text property.
log everyimagelocation(text:"Eggplant") -- Logs a list of hot spot coordinates for every occurrence of the text found.
Example: Using a Repeat Loop with everyImageLocation:
This example uses everyImageLocation to click each found instance of a captured image, using a repeat loop:
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
Or, to do the same thing, but using alternate syntax:
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
Example: Referring to a Specific Occurrence of a Found Text String Using OCR:
This example clicks the penultimate (second to last) item in the list of occurrences of the text (using OCR):
click the penultimate item of EveryImageLocation(text:"AddressField")
When you call the EveryImageLocation function, you can immediately call the result to return ImageInfo for every image represented in EveryImageLocation:
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
You can use AI searches with this function.
For more information, see Find by Description.
Behavior: Searches the SUT for all occurrences of the elements described (Find by Description), images specified (captured image search), or text strings (OCR).
Returns a list of the rectangle coordinates for every occurrence of the elements, images, or text. Coordinates are listed in the order in which they are found, where elements, images, and text closest to the top left corner of the SUT are found first. For Find by Description and OCR searches, the ImageRectangle is automatically fitted around the element or text string as it appears on the SUT. If no element, image, or text is found, EveryImageRectangle returns an empty list.
Parameters: One or more descriptions (for Find by Description searches), one or more Image References (for captured image searches), or one or more Text Properties (for OCR searches).
Syntax:
EveryImageRectangle( imageOrTextReference )
Returns: The rectangle coordinates of every instance of the described element(s) (Find by Description), provided captured image(s), or text (OCR).
Example: Using a Find by Description Search:
Use an AI-powered Find by Description search to locate every instance of a trash can icon on the SUT screen and print the associated rectangle coordinates in the Run window:
put everyimagerectangle(description:"trash can icon") -- Locates all of the trash can icons on the screen of the SUT and returns a list of recangle coordinates for every occurance
Example: Using Captured Image Searches:
This example returns a list of all instances of two different captured images:
put EveryImageRectangle("TotalAmountLabel", "ItemizedAmountLabel") -- Returns a list of rectangle coordinates for every occurrence of the images.
This example searches for a specific captured image, within a specified portion of the screen:
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: Using everyImageRectangle to Identify a Status Label:
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:
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.
ImageFound Function
You can use AI searches with this function.
For more information, see Find by Description.
Behavior: Searches the SUT for the elements described (Find by Description), images specified (captured image search), or text strings (OCR). Returns true if the element, image, or text is found, and false if it is not found. A maximum wait time parameter allows time for an element/image/text to be found before false is returned.
Parameters: One or more descriptions (for Find by Description searches), one or more Image References (for captured image searches), or one or more Text Properties (for OCR searches).
Syntax:
ImageFound( imageOrTextReference )
Returns: True or False.
Example: Using a Find by Description Search:
Use an AI-powered Find by Description search to determine if a web page has loaded, by looking for an element that is expected to appear on that page:
If imagefound(description:"Sign in button") then log "the page has loaded" -- Upon a successful search, this logs "The page has loaded."
Examples: Using a Captured Image Search:
Uses a captured image to locate an element, and then either click it, or close the application using a keyboard shortcut:
if ImageFound(ImageName:"OKButton") then -- Checks whether the image is found
click FoundImageLocation() -- If ImageFound returns true, uses the FoundImageLocation function to click the stored location where the image was found by the ImageFound function
else
TypeText AltKey,F4 -- If ImageFound returns false, executes a keystroke to close the application
end if
Including the ImageName property is required when passing additional image search properties:
Repeat until ImageFound(ImageName:"NextButton",WaitFor:0) -- This repeat loop iterates until the ImageFound function returns true.
Typetext PageDown -- Sends a Page Down keyboard action to scroll down the page.
Wait 2 -- Waits 2 seconds to allow the application to stop moving after the scrolling action.
if the repeatindex is greater than 5 then throw "Image Not Found:", "NextButton not found when scrolling." -- This conditional statement checks to see whether the repeat loop has iterated more than 5 times, and if so, throws an exception to stop the execution.
end repeat
Example: Using an OCR Text Search:
To find text using OCR, provide a text property. Setting a search area using SearchRectangle() is useful when searching for text.
if imagefound(text:"Hello!", SearchRectangle:("Image1","Image2"))
then
click foundimagelocation()
log "clicked it!"
else
logerror "didn't find the word"
end if
A maximum time of 0 causes EPF to perform an immediate search, without refreshing the Viewer window or repositioning the mouse in a further attempt to find the image. This is the fastest way to search for an image that may not be present.