Testing in a different browser language

3,232 views
Skip to first unread message

Thomas

unread,
May 17, 2012, 3:59:09 AM5/17/12
to Selenium Users
Hi,

Ok, here's what I want to do:

After running some tests in my local browser language (let's call it
baseLanguage) I open the browser, change its browser language to a
different one (let's call it otherLanguage) and then run the same
tests using Eclipse and Java.

Here's what's happening:

After I change the baseLanguage to otherLanguage and try to run the
tests the browser starts with the baseLanguage instead of
otherLanguage. However it's working with IE but not with FF or Chrome
and it's working with every browsers when I run them manually, not
from the test.


I'm using Selenium 2.21, Eclipse (Galileo) Java EE IDE for Web
Developers
Browser versions: Internet Explorer 9.0, Firefox 12.0, Chrome version
19.0.1084.46 m

Please give me a hint how to it!

Thomas

Peter Gale

unread,
May 17, 2012, 4:10:48 AM5/17/12
to seleniu...@googlegroups.com
Perhaps you'd like to share some code to illustrate what you're doing before anyone tries to tell you what you're doing wrong.

> Date: Thu, 17 May 2012 00:59:09 -0700
> Subject: [selenium-users] Testing in a different browser language
> From: archr...@gmail.com
> To: seleniu...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>

Krishnan Mahadevan

unread,
May 17, 2012, 4:12:58 AM5/17/12
to seleniu...@googlegroups.com
With firefox I think the reason why it works for you manually is because your language preferences got saved into your profile (default profile).

But when you run your test, WebDriver creates a dummy profile and spawns firefox using that profile. The dummy profile would only have the default settings of firefox and wouldnt have any customizations that you did to your browser.

To get Firefox to work, here is what you would need to do :

FirefoxProfile profile = new ProfilesIni().getProfile("default");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);

FirefoxDriver driver = new FirefoxDriver(dc);

With IE, the reason why it works is both manually as well via automation is because IE doesnt work with profiles. All settings that you do to IE is saved somewhere globally (Registry perhaps ?)

I think the same is the case with Chrome as well (Similar to firefox)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"




Thomas

Thomas

unread,
May 17, 2012, 4:54:57 AM5/17/12
to Selenium Users
Thanks for your reply Peter! What I'm trying do is:

1. Run the test
2. Change browser language manually
3. Run the same test with the new browser language

Let's say my code is:

WebDriver driver = new FirefoxDriver();
String url = "http://search.yahoo.com/";
driver.get(url);
WebElement firefoxElement = driver.findElement(By.name("p"));
firefoxElement.sendKeys("software");
firefoxElement.submit();

On máj. 17, 10:10, Peter Gale <peterjeffreyg...@hotmail.co.uk> wrote:
> Perhaps you'd like to share some code to illustrate what you're doing before anyone tries to tell you what you're doing wrong.
>
>
>
>
>
>
>
> > Date: Thu, 17 May 2012 00:59:09 -0700
> > Subject: [selenium-users] Testing in a different browser language
> > From: archrod...@gmail.com

Krishnan Mahadevan

unread,
May 17, 2012, 4:56:15 AM5/17/12
to seleniu...@googlegroups.com
Thomas,
I suggest you go through my response on this, in the same thread.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


Thomas

unread,
May 17, 2012, 4:58:46 AM5/17/12
to Selenium Users
Thank you reply Krishnan and also for the explanation! Now it's
working with FF but how do I accomplish the same with Chrome?

Thomas

On máj. 17, 10:12, Krishnan Mahadevan

Krishnan Mahadevan

unread,
May 17, 2012, 5:01:19 AM5/17/12
to seleniu...@googlegroups.com
You would need to spawn Chrome with this commandline flag :  http://peter.sh/experiments/chromium-command-line-switches/#lang 

and see if that helps .

Read here to learn how to specify flags via WebDriver code : http://code.google.com/p/selenium/wiki/ChromeDriver#Starting_Chromium_with_Specific_Flags



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Thomas

unread,
May 17, 2012, 5:17:56 AM5/17/12
to Selenium Users
I tried to use the --lang switch at the end of the target line of the
chrome exe (ex.: chrome.exe --lang) and I also tried this:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--
lang"));
WebDriver driver = new ChromeDriver(capabilities);

None of them seemed to work. By the way, the ChromeDriver(Capabilities
capabilities) constructor is deprecated.

On máj. 17, 11:01, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> You would need to spawn Chrome with this commandline flag :http://peter.sh/experiments/chromium-command-line-switches/#lang
>
> and see if that helps .
>
> Read here to learn how to specify flags via WebDriver code :http://code.google.com/p/selenium/wiki/ChromeDriver#Starting_Chromium...

Thomas

unread,
May 18, 2012, 4:22:51 AM5/18/12
to Selenium Users
Meanwhile I found out how to use this switch correctly but is there a
better way to do it like in firefox?
So there would be no need to modify the code again and again...

Krishnan Mahadevan

unread,
May 18, 2012, 4:25:09 AM5/18/12
to seleniu...@googlegroups.com
Thomas,
If its a chrome switch, then why would you need to keep modifying your code repeatedly ? I am not able to get that part of your statement. Care to elaborate ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


PeterJef...@hotmail.co.uk

unread,
May 18, 2012, 4:33:01 AM5/18/12
to Selenium Users
Can't you just create some sort of command line switch which tells
your progrm which lanaguage you want the browser to be run in?

Thomas

unread,
May 18, 2012, 5:06:45 AM5/18/12
to Selenium Users
Dear Krishnan and Peter!

If I use switches, every time I want to run the test in a different
language I will have to modify the code. Here's a little insight I've
just created:

ChromeOptions options = new ChromeOptions();
options.setBinary(PATH/TO/CHROME/EXECUTABLE));
String browserLanguage = "--lang=es"; // set for Spanish
options.addArguments(browserLanguage);

WebDriver chromeDriver = new ChromeDriver(options);
String url = "http://www.example.com";
chromeDriver.get(url);

// run tests

chromeDriver.quit();


This above code works fine with a particular language (currently set
to Spanish) but when it comes to running the tests I need modify it. I
would like to have a more elegant way to do it so there would be no
need to change the code just watch it run perfectly just like in case
of firefox.

On máj. 18, 10:33, "PeterJeffreyG...@Hotmail.co.uk"

PeterJef...@hotmail.co.uk

unread,
May 18, 2012, 5:09:15 AM5/18/12
to Selenium Users
Thomas

You could get your code to read the swithc and then get your program
so execute whichever version of the code you need to set the browser
language as required.

Then there would be no on-the-fly-code changes required at all.

Peter

Krishnan Mahadevan

unread,
May 18, 2012, 5:10:35 AM5/18/12
to seleniu...@googlegroups.com
Here's how you redefine it.
ChromeOptions options = new ChromeOptions();
options.setBinary(PATH/TO/CHROME/EXECUTABLE));
String browserLanguage = "--lang=" + System.getProperty("LanguageToUse");     // set for Spanish
options.addArguments(browserLanguage);

WebDriver chromeDriver = new ChromeDriver(options);
String url = "http://www.example.com";
chromeDriver.get(url);


When you run this you use the JVM VM Argument approach and send -DLanguageToUse=es or -DLangaugeToUse=il or whatever you want send.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Thomas

unread,
May 18, 2012, 5:24:54 AM5/18/12
to Selenium Users
Dear Peter and Krishnan,

I'm currently doing something similar to your suggestions: I'm reading
the switches from an external file so I don't need to modify the code
but I still need to modify the external file every time I change
language. There should be another solution which requires no
modification at all...

On máj. 18, 11:09, "PeterJeffreyG...@Hotmail.co.uk"

Krishnan Mahadevan

unread,
May 18, 2012, 5:26:56 AM5/18/12
to seleniu...@googlegroups.com
Why wouldnt the VM Argument approach work for you, if you opt it instead of reading the language setting from an external file ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


PeterJef...@hotmail.co.uk

unread,
May 18, 2012, 5:27:06 AM5/18/12
to Selenium Users
What external file are you modifying manually and why can't you
recreate it directly from your program?

Thomas

unread,
May 18, 2012, 5:33:01 AM5/18/12
to Selenium Users
I'm modifying an external file containing that switch I want to use.
Let's say it contains: "--lang=de"
And I read that switch from the program and the next time I want to
test in English i need to modify it to "--lang=en"
What do you mean by "why can't you recreate it directly from your
program?"

On máj. 18, 11:27, "PeterJeffreyG...@Hotmail.co.uk"

Krishnan Mahadevan

unread,
May 18, 2012, 5:36:55 AM5/18/12
to seleniu...@googlegroups.com
Thomas,
There is no way in which you can go about doing this.

You would either need to update the LANGUAGE settings everytime in this external file that you are referring to (or) 
Rely on VM arguments mechanism (for e.g.,)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


PeterJef...@hotmail.co.uk

unread,
May 18, 2012, 5:38:37 AM5/18/12
to Selenium Users
I mean ... use the switchign approach as detailed by Krishnan, then re-
write the external file from within your program.

I don't know how to explain that any more clearly, so perhaps we have
a language problem here too!? ;)

Thomas

unread,
May 18, 2012, 5:54:25 AM5/18/12
to Selenium Users
If I use that switching approach and then rewrite the external file
from the program, I will still need to modify the VM arguments later.
And yes it can be hard to explain a no ordinary problem in a foreign
language and to understand the replies correctly. You should try it
one time :))

Thank you Krishnan and Peter for guiding me in this issue! I now
officially end this topic.

Thomas

On máj. 18, 11:38, "PeterJeffreyG...@Hotmail.co.uk"

Felix

unread,
Dec 24, 2012, 1:44:44 AM12/24/12
to seleniu...@googlegroups.com
Hi All,
Now I use the selenium server to start the chrome browser, your solution is use chromedriver, but how deliver the lang=jP swith to selenium server?
 

 
 
 
 
 
 
 
在 2012年5月17日星期四UTC+8下午3时59分09秒,Thomas写道:
Reply all
Reply to author
Forward
0 new messages