Selenium for Internationalization

Configure IDE for unicode chracter display
Using ECLIPSE as an example, click on Windows -> Preference -> General -> Workspace, and choose ‘UFT-8’ for ‘Text File Encoding’, then apply.

Figure 1: Configure IDE for Unicode Character Display

Configure Maven Encoding to use UFT-8
Configure encoding via property in pom.xml:

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″
[…]

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
[…]
</project>

Or via maven resources plugin:

<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″
[…]

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

Now when you run your test against international site, all foreign characters shall be displayed fine, fine in resource file, source code and console.

Localized Site is Implemented via Resource Bundle
Business logic remains the same, so the major change lies on the front end: the display text is in different languages. For each language, we usually have a plain text file holding all the display text for that country in the form of key:value format. This sort of file is called resourceBundle file.

Figure 2: Resource Bundle

Sample ResourceBundle files:

All display texts are retrieved from these resource bundle files.

Automation: Retrieve Display Text from Resource Bundle Files
The underlying logic remains the same, the things that need change:
1. URLs for AUT: Don’t hard-code any URLs for AUT. Instead, make it configurable and retrieve it from System Property files
2. Locator by text, like drop down option chosen by option text
3. Verification: When verifiying text on the page, always retrieving expected text for Resource Bundle file like this:

Load appropriate locale file when automation starts:

File file = new File(“folderHoldingPropertyFiles”);
URL[] urls = {file.toURI().toURL()};
ClassLoader loader = new URLClassLoader(urls);
Locale locale;
ResourceBundle resourceBundle ;
if(language.equalsIgnoreCase(“de”))
{ deutchLocale = new Locale(“de”, “DE”);
ResourceBundle resourceBundle = ResourceBundle.getBundle(“Resources_de.properties”, deutchLocale, loader);
else if (language.equalsIgnoreCase(“fr”))
{ franceLocale = new Locale(“fr”, “FR”);
ResourceBundle resourceBundle = ResourceBundle.getBundle(“Resources_fr.properties”, franceLocale , loader);
}else …..

In page object classes, and verification library classes, if any, retrieve display text like this:

String submit_label = resourceBundle.getString(“SUBMIT_LABEL”));

Also read: Script to VPN Your machine to another Country for Internationalization Test

Leave a Reply

Your email address will not be published. Required fields are marked *