Tuesday, September 9, 2008

Automation in Localization

Demo Project
Download below HTML file in DOC file

When you are doing an automation of a Web Site or an Application and if it is in more then one languages, your recorded script will fail when you will switch to another localized application.

In that case you can use any of the below method or the mixture of the methods to automate the localized application.

  1. Create the different repositories and different scripts for different languages. But then if your application is in many languages you will end up with too many scripts and then it will become hard to maintain all the scripts and keep track of it.

  2. The second way is to use if and else condition and for the part of the code which fail while changing the language. Because most of the time in the web application when you switch the language only buttons and links are not identifiable. But all other objects, like edit box, checkbox, radio buttons are easily identifiable

For Example:

Take a google.com site as an example. We are just going to enter some text in the search box and then will hit the Search Button to search.

If you will record the script from the google.com for the above test case, and then if you will move to the google.fr (French Version) or google.es ( Spanish Version ) it’s going to be fail. The script will fail at the point of pressing the Search button. So to localize this you can us the IF END condition as follows

Code:

Browser("Google").Page("Google").WebEdit("q").Set "qtp-help.blogspot"

If Environment("Language") = "EN" Then
Browser("Google").Page("Google").WebButton("name:=Google Search")
End If

If Environment("Language") = "ES" Then
Browser("Google").Page("Google").WebButton("name:=Buscar con Google")
End If

If Environment("Language") = "FR" Then
Browser("Google").Page("Google").WebButton("name:=Recherche Google")
End If

If Environment("Language") = "ED" Then
Browser("Google").Page("Google").WebButton("name:=Google-Suche")
End If

This works for the objects that are not identifiable in another language, But what about text checkpoints?? You can do the same things for the text checkpoints.

Just record the checkpoint in all the languages and put it in the IF and Else clause.

For example. If you need to verify the text between the “Advance Search” and “Language Tools” you can do it as follows.


If Environment("Language") = "EN" Then
Browser("google - Recherche Google").Page("Google").Check
End If

If Environment("Language") = "ES" Then
Browser("google - Recherche Google").Page("Google").Check CheckPoint("Google_ES")
End If

If Environment("Language") = "FR" Then
Browser("google - Recherche Google").Page("Google").Check CheckPoint("Google_FR")
End If


If Environment("Language") = "DE" Then
Browser("google - Recherche Google").Page("Google").Check CheckPoint("Google_DE")
End If

This seems a good solution but it has it has some disadvantages. The scripts become lengthy if you have application in too many languages or the in identifiable objects are much more.

So what to do now?? There is a third way (as it always). And it is easy than above two.

  1. Language Specific OR
    The third method is to convert the part of the script to keyword driven which fails. And put all the keyword in the separate file and execute the particular file based on the localize version you are testing.

For Example take the same above test case where we have to enter the text in the search box and have to press the “Google Search” Button. And the checkpoint that verifies the text between the “Advance Search” and the “Language Tools”

To execute the above test case we will make the four different text files, one for each language and will put all the keywords in those files as follows.

Keyword = “Property:=Value”

And IF you require more then one property to identify the object use as follows:


Keyword = "Property1:=Value1"&","&"Property2:=Value2"&”,”…..


EN_Obj.txt file contains the keywords for the English language, DE_Obj for the German language and so on for the other languages.


En_Obj.txt

Search="name:=Google Search"
Environment("Language_Tools") = "Language Tools"
Environment("Advanced_Search") = "Advanced_Search"
Environment("Preferences") = "Preferences"

DE_Obj.txt
Search="name:=Google-Suche"
Environment("Language_Tools") = "Sprachtools"
Environment("Advanced_Search") = "Erweiterte Suche"
Environment("Preferences") = "Einstellungen"

FR_Obj.txt
Search="name:=Recherche Google"
Environment("Language_Tools") = "Outils linguistiques"
Environment("Advanced_Search") = "Recherche avancée"
Environment("Preferences") = "Préférences"

ES.Onj.txt
Search="name:=Buscar con Google"
Environment("Language_Tools") = "Herramientas del idioma"
Environment("Advanced_Search") = "Búsqueda avanzada"
Environment("Preferences") = "Preferencias"


As now we have separated the keyword Search. If you are not getting why we have taken the environment variable. Don’t worry we will discuss it later. But as now it’s all about accessing the links and buttons and other objects.


Now you have to execute one of the above files, based on the localized version of you application you are testing. I have used Environment variable to tell script in which language the application is but you can use any of the function that automatically retrieve the language of the application.


Environment("Language")="ES"

‘All four files above are located in the test directory
ExecuteFile Environment("TestDir")&"\"&Environment("Language")&"_Obj.txt"

Browser("Google").Page("Google").WebEdit("q").Set "qtp-help.blogspot"

Browser("Google").Page("Google").WebButton(Search).click

Here we have use a variable which is common in all the files and contains the string for the descriptive programming.

We can use the same method for the text checkpoints too but it’s little tricky as you can’t use the variable in the text checkpoint, you need to use the Environment variable instead. This is way we have put the environment variable in the files, for the text checkpoint.

Code:
Browser("Google").Page("Google").Check CheckPoint("Google")

If you will look at the screen shot of the checkpoint, you will find that all the texts, Checked Text, Text Before and Text After are the environment variable and their values are coming from one of the above four text files.





  1. Regular Expression:
    The fourth method is bit easy then all the above methods. You can use the regular expression in OR (Object Repsoitry) or with DP ( Descriptive Programming ) to identify the Objectes that fails while switching the lanuguge.

Descriptive Programming.
Just take the same above test case

Browser("Google").Page("Google").WebEdit("q").Set "l10n"
Browser("Google").Page("Google").WebButton("Name:=Google Search|Buscar con Google|Recherche Google|Google-Suche").Click

Here we have use the regular expression to click the button having string Google Search ( English ) or Buscar con Google ( Spanish ) or Recherche Google ( French ) or Google-Suche ( German ).

Object Repository
You can use the same regular expression as the property value in the OR as follows.



If you will check the Value of the property “Value” you will find it’s a same regular expression we have used in the DP.

This methods is easy to use but we can not use the same method for the Text Checkpoint as there is no way you can use regular expression in the “Text Before” and “Text After”


0 comments:

Post a Comment