Working with Text in Eggplant Functional
When you need to find text, remember that you can capture an image of the text and let your script perform an image search. This works best in situations where the text is static and unchanging, such as button text. However, for scenarios where the text is dynamic or the text value to be searched isn't known ahead of time, Eggplant Functional (EPF) provides on an optical character recognition (OCR) engine to search the screen for the text string on the system under test (SUT).
There are multiple ways of finding text on the SUT:
When to Use Images vs. OCR to Find Text
While you can use OCR almost any time you need to search for text on the SUT, it should be treated as a secondary option to captured images. Take a moment to evaluate the situation to see if using a captured image is feasible or if you need to use OCR.
In situations that fit the descriptions below, try using a captured image before turning to OCR:
- The text is not dynamic.
- You know what text you are looking for ahead of time (it is not being pulled in from an external source during the script run).
- You do not need to read the text off of the SUT using
ReadText
, or the text can be instead copied using theRemoteClipboard
function and returned to the script that way. - Your test is against a single platform or system (not cross-platform or cross-browser).
- The text you are working with is set to a very small font size, or an abnormally large size.
OCR is well-suited to the following situations:
- You do not know the text you are looking for ahead of time, but the script will have access to that information by the time the search is conducted.
- The font, size, or color of the text can vary.
- Your testing includes a variety of browsers, and different browsers can render fonts differently.
- You need to read a text value from the SUT and bring that information back into your script for further testing or to record in an external data file.
Image Searches
In many cases, you can find text on the SUT the same way you would find any other item on the SUT: by capturing an image of the text and searching for that image in your script. Captured images are easy to use, and very reliable.
For images that contain text, the search type setting Smoothed for Text
, accounts for anti-aliased text that might appear in the image. This setting allows for more successful image matches of images that contain text. This can be set at the time of image capture, or in your script using the searchType
property with your image search.
Note: This method is only for finding text on the
Examples:
Click "HelpMenu" -- Finds the image of the Help menu, then clicks it
Click (imageName:"HelpMenu", searchType:"smoothed for text") -- Finds the image of the Help menu using the smoothed for text search type, then clicks it
For more information about image searches, see Finding Images.