How to change the language preferences in Selenium Webdriver
Before moving to language preference lets talk about why it is required and why we are changing this ?
1-Some time in real time you will face some situation where you need to check whether your application support multiple languages or not. In other words your application is globally working or not.
2-To check this we can change the language preference and open the same application with that language so if your application support that particular language it will open the application the same language and if not supported then by default it will open in English.
For Example- Open Google in Chinese and Facebook in Chinese so if they support Chinese language so both application will open in Chinese language
To implement this we need to change the browser setting to achieve this we can use FirefoxProfile class and setPreferences method
Scenario - Open Google in Chinese language and verify the total page translated or not.
To check these setting you can open firefox browser and in url type about : config
Now check the properties which we need to change in this scenario we need to modify intLaccept_languages and by default it set to en (English)
Let's implement the same in Selenium Webdriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;
public class TestFFLangua {
@Test
public void testFFP(){
// This will create firefox profile
FirefoxProfile fp=new FirefoxProfile();
// this will change the language preference and zh is the locale for China
fp.setPreference("intl.accept_languages", "zh");
// now pass this fp object to FirefoxDriver
WebDriver driver=new FirefoxDriver(fp);
driver.manage().window().maximize();
driver.get("https://www.facebook.com");
}
}
1-Some time in real time you will face some situation where you need to check whether your application support multiple languages or not. In other words your application is globally working or not.
2-To check this we can change the language preference and open the same application with that language so if your application support that particular language it will open the application the same language and if not supported then by default it will open in English.
For Example- Open Google in Chinese and Facebook in Chinese so if they support Chinese language so both application will open in Chinese language
To implement this we need to change the browser setting to achieve this we can use FirefoxProfile class and setPreferences method
Scenario - Open Google in Chinese language and verify the total page translated or not.
To check these setting you can open firefox browser and in url type about : config
Now check the properties which we need to change in this scenario we need to modify intLaccept_languages and by default it set to en (English)
Let's implement the same in Selenium Webdriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;
public class TestFFLangua {
@Test
public void testFFP(){
// This will create firefox profile
FirefoxProfile fp=new FirefoxProfile();
// this will change the language preference and zh is the locale for China
fp.setPreference("intl.accept_languages", "zh");
// now pass this fp object to FirefoxDriver
WebDriver driver=new FirefoxDriver(fp);
driver.manage().window().maximize();
driver.get("https://www.facebook.com");
}
}
No comments:
Post a Comment