I am new to testing and have a question about how can we verify the local language using Selenium. Suppose that I have some link which lets me choose the language, so if I choose a language how can I verify that?
By anything on the page! Let's assume our page is only made of one element, either
<div>
It's time to kick ass and chew bubble gum!
</div>
or
<div>
Il est temps de botter le cul et mâcher de la gomme à bulles!
</div>
Then, with Selenium, you can get the element, get the inner text and verify! Example in Java:
// assuming driver is a good WebDriver instance
WebElement elem = driver.findElement(By.xpath("//div"));
if (elem.getText().contains("kick ass")) {
System.out.println("It's English!");
} else if (elem.getText().contains("botter le cul")) {
System.out.println("It's French!");
}
As of Java 7, you can even use a switch-case on a String, so you can digestedly test against many, many languages.
Well, you can
Good evening
to Dobrý večer
(that was in Czech ;) )We use dictionary files for l10n. Dictionary is an xml file with strings stored like <string key="Cancel">Cancel</string>
.
So for testing purposes we replace all </string>
with something like @@@</string>
and replace all spaces between <string key="...">
and </string>
with '_' (can be done in notepad++ with ctrl+h, spaces can be replaced with the help of this answer for example). Then we select language that corresponds to modified dictionary at our website. Next step is done by Selenium IDE script: browsing through the whole web site and storing pages' text with the use of Selenium IDE command storeBodyText | text
. Then parsing and echo all words that is not ended with @@@ and analyze if it ok or the word that should be translated is hard-coded.
Not pure automation but better than nothing :) I think this approach can be applied not only for xml-dictionary files but for any storage you use for your strings.
PS. If you don't want to perform localization testing but just want to be sure that by clicking on link some language is applied (I'm afraid this is exactly what you are looking for), after you click at your link you can get text from any element and compare it with expected text (storeText(locator, variableName)
for IDE).
<!-- Using Selenium IDE -->
<tr>
<td>storeAttribute</td>
<td>//html@lang</td>
<td>language</td>
</tr>
<tr>
<td>echo</td>
<td>The label is ${language}</td>
<td></td>
</tr>