If the website that we test, deals with many languages say English,Magyar,French,Spanish, then we need to write our tests such that, it would work when the site is loaded in any of the languages.
Step 1:
To localize the tests , we first need to create properties files for each of the languages.
In the sample below I have assumed that we are going to load the website in Magyar language and the property file for Magyar is present in the path,
D:\\Automation\\Framework\\Properties.
The content of the file will be something like,
SIGN_OUT=Kilépés
MY_HOME_PAGE=Kezdőlapom
SETTINGS=Beállítások
Here "SIGN_OUT", "SETTINGS" are the Keys which have the corresponding Values "Kilépés","Beállítások".
We can copy and paste the values (the ones onto the right) from the website that is to be automated into the notepad.
Likewise we need to create Key - Value pair for all the required words which will be used in our test.
In our case we can save as hu.txt (encoding - UTF8)
Step 2:
Next step is to convert this into ASCII format.
To do this enter the command mentioned below in command prompt .
Syntax:
native2ascii -encoding utf8 source.txt destination.txt
Ex:
Note:
Open the directory where your source text file is, before entering the command .
The destination file, hu_ascii will be created under "D:\\Automation\\Framework\\Properties".
The values in it will be like ,
After conversion :
SIGN_OUT=Kil\u00e9p\u00e9s
SETTINGS=Be\u00e1ll\u00edt\u00e1sok
Now we can use this encoded text in our webdriver tests.
Step 3:
For loading the respective property file, I use a method such as this
public Properties loadProp(String lang) throws FileNotFoundException,
IOException {
Properties prop = new Properties();
prop.load(new FileInputStream(
"D:\\Automation\\Framework\\Properties\\"
+lang+"_ascii.txt"));
System.out.println(prop.get("SETTINGS"));
return prop;
}
Step 4:
Now that the language's corresponding prop file is loaded, it can be used in any of the methods like ,
public static WebElement sel_Link(Properties prop,String menuitem){
we = driver.findElement(By.xpath("//li/a[text()='" + prop.getProperty(menuitem) + "']"));
return we;
}
That's all for now.
Hope this helps ..
Step 1:
To localize the tests , we first need to create properties files for each of the languages.
- Such files have key and value pairs.
- It should be a .txt file , saved with Encoding as UTF-8 format.
- It can be saved under the project which we are working on.
In the sample below I have assumed that we are going to load the website in Magyar language and the property file for Magyar is present in the path,
D:\\Automation\\Framework\\Properties.
The content of the file will be something like,
SIGN_OUT=Kilépés
MY_HOME_PAGE=Kezdőlapom
SETTINGS=Beállítások
Here "SIGN_OUT", "SETTINGS" are the Keys which have the corresponding Values "Kilépés","Beállítások".
We can copy and paste the values (the ones onto the right) from the website that is to be automated into the notepad.
Likewise we need to create Key - Value pair for all the required words which will be used in our test.
In our case we can save as hu.txt (encoding - UTF8)
Step 2:
Next step is to convert this into ASCII format.
To do this enter the command mentioned below in command prompt .
Syntax:
native2ascii -encoding utf8 source.txt destination.txt
Ex:
native2ascii -encoding utf8 hu.txt hu_ascii.txt
Note:
Open the directory where your source text file is, before entering the command .
The destination file, hu_ascii will be created under "D:\\Automation\\Framework\\Properties".
The values in it will be like ,
After conversion :
SIGN_OUT=Kil\u00e9p\u00e9s
SETTINGS=Be\u00e1ll\u00edt\u00e1sok
Now we can use this encoded text in our webdriver tests.
Step 3:
For loading the respective property file, I use a method such as this
public Properties loadProp(String lang) throws FileNotFoundException,
IOException {
Properties prop = new Properties();
prop.load(new FileInputStream(
"D:\\Automation\\Framework\\Properties\\"
+lang+"_ascii.txt"));
System.out.println(prop.get("SETTINGS"));
return prop;
}
Step 4:
Now that the language's corresponding prop file is loaded, it can be used in any of the methods like ,
public static WebElement sel_Link(Properties prop,String menuitem){
we = driver.findElement(By.xpath("//li/a[text()='" + prop.getProperty(menuitem) + "']"));
return we;
}
That's all for now.
Hope this helps ..
Pay It
Forward...
Lots
of energy ..
DR