Many Eggplant Functional customers have a requirement to test the scripts they develop in multiple languages. Optical character recognition (OCR) is a powerful feature of Eggplant Functional that facilitates text recognition across dozens of languages, making localization testing much easier. So how can Eggplant Functional customers create a single automation script that can test the scripts they develop in any language? In addition, OCR does not yet support all languages. So how can Eggplant Functional customers create a script that not only leverages OCR, but also leverages images so that unsupported languages can be tested? Below is a set of examples that show how this can be done.
The method described in this article assumes the following are in place:
- For each language with OCR support that you need to test, you maintain a localization data file that contains the translations of all strings that need to be validated. The examples below assume your localization data files use UTF8 encoding.
- For each language that is not supported by OCR, you maintain a separate suite of images of each string that needs to be validated.
The Translate script handles property lists passed by the test script and manipulates them into the required OCR search or image search, depending on the language name in the Language global variable.
params ImagePropertyList //Receives the property list passed by the test script.
//Manage a list of OCR languages. You must have a localization data file of translations for each of these languages.
set OCRLanguages to ("Spanish","English")
//Manage a list of image-only languages (no OCR support). You must have a suite of images for each of these languages.
set ImageLanguages to ("Hebrew","Tongan")
//Determines whether the search should use OCR or images.
if Language is among the items of OCRLanguages
set Type to "text"
set IsOCRLanguage to true
set WordtoTranslate to ImagePropertyList's Name
else if Language is among the items of ImageLanguages
set Type to "image"
set TranslatedWord to ImagePropertyList's Name
if the InitialSuites is not Language then set the InitialSuites to Language //Uses the InitialSuites global property to point the test script at the appropriate suite of images for the given language. The code assumes the suite has the same name as the language (i.e. "Hebrew").
throw "Language global variable value problem", "Language is not defined as OCR or image language."
//Creates a property list of translated strings if one doesn't already exist for the current language.
if IsOCRLanguage is true and if Translator.(Language) is empty then
put file resourcePath(Language&".txt") into LocalizationData
//Example contents for a LocalizationData file named Spanish.txt, stored in the suite Resources.
//PaperSize,Tamaño de papel
//InkColor,Color de tinta
repeat with each line Translation of LocalizationData
put the trim of item 1 of Translation into ElementName
put the trim of item 2 of Translation into String
set Dictionary.(ElementName) to String
set Translator.(Language) to Dictionary
if IsOCRLanguage is true then put Translator.(Language).(WordToTranslate) into TranslatedWord //Retrieves the translation for the element from the property list of translations, runs only if the current language is an OCR language.
set ImagePropertyList to ((type):TranslatedWord) adding properties of imagePropertyList //Combines the original property list passed from the test script with the property that specifies whether the search should use images or OCR.
remove property ("name") from ImagePropertyList //Cleans up the property list to remove the now redundant name: property.
if IsOCRLanguage is true then add property (Language:(Language)) to ImagePropertyList //Adds the OCR language: property and value if the language is an OCR language.
return ImagePropertyList //Returns the new image or OCR property list back to the original search in the test script.
Test Script Code
Use code as shown in the following examples to create your test scripts. This localization testing script should look very similar to a regular script, but with the addition of the references to the Translate script. The Translate script processes the image or OCR property list that is passed to it, determines the appropriate image or OCR string to search for based on the language name in the Language global variable, and returns a new image or OCR property list to the test script.
params Environment //Receives the name of the language you need to test.
//Using global variables allows the values in the variables to easily pass between the test script and the Translate script many times
set Language to Environment
set the InitialSuites to empty //Resets the InitialSuites at the beginning of the execution - assumes you are not using InitialSuites for anything other than localization image libraries.
WaitFor 10, Translate (name:"Inkcolor", searchRectangle:("PrinterSettings_Header","OK_Button"))//"InkColor" is the name of an image in the images suites or is used in the localization data file.
WaitFor 10, Translate (name:"PaperSize") //The Translate script expects the use of the name: property when referencing the element you want to identify on the screen.
Click Translate (name:"TrayNumber", waitfor:25)