I want to execute my Selenium tests in different languages. Is it possible to change the language of an existing WebDriver at runtime or do I have to recreate the browser instance?
Right now I'm only using Firefox, but I want to execute tests in different browsers at some later point.
In Firefox I set the language like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "de");
WebDriver driver = new FirefoxDriver(profile);
I also implemented a WebDriverPool, which holds a WebDriver instance so it can be shared among tests. If the language can only be set at creation time, I could hold an instance for every locale.
All in all I wonder if I miss something here. Why is it so hard to change the language? shouldn't there be a method like WebDriver.setAcceptLanguages(Locale)
?
In a nutshell I have these questions:
- Why isn't there
WebDriver.setAcceptLanguages(Locale)
? - How to change the language for the dirrerent WebDrivers?
- Can I change the language at runtime?
- How did you guys implement your WebDriverPool or do you recreate them everytime?
You can also do it through about:config in firefox. But you need to use Actions to manipulate it.
Below a java piece of code
I ended up creating a WebDriverPool that creates one instance for every combination of WebDriver type (e.g. FirefoxDriver.class) and Locale (e.g. en_US). Maybe this is usful for someone.
I am afraid that the whole idea of WebDriver is to act like browser - so you can change the language of the browser, but you have to change the locale in the Operating system, or hope that the application will do it for you.
For instance - German number format separates decimal number by comma and English one by dot. If you want to test, how the number format behaves in English locale and in German locale, you can do it only by these two approaches:
To answer your questions:
I would do it like this (Java code):
I am afraid you have to close the browser and open it again with different language.
BTW the above bit of code assumes, that the web application changes the way how to show numbers to the user based on browser language.