My Thoughts: Changing the User Language Locale using WebDriver (Selenium2)

Friday, May 18

Changing the User Language Locale using WebDriver (Selenium2)


Most of the time Websites use the User "Default Language Settings" to display the website look and feel.

If we want to check whether our application is properly internationalized , then we will manually change the language preferences in the browser itself.

But if we want to check the same using webDriver then we have programatically change the user language preferences. And it's simple :)

If you are using Firefox then you can change the Language preferences by the below code

intl.accept_languages= "Language Code"

Here is the sample code using TestNG framework.
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.WebDriver;

public void UserLocale(){

WebDriver  driver;

@BeforeTest
public void setUpDriver() {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages","sl");   
driver = new FirefoxDriver(profile);
}

@Test
public void start(){
driver.get("http://google.com");
}

}
If you run the above code then google will be opened in Sloveninan Language and here is the output .. !! :)

Google.com in Sloveninan Language

No comments:

Post a Comment