Activating chrome language flags when activating from protractor (selenium)
Asked Answered
C

2

5

I'm writing end to end tests with Protractor for an angular website.

We have to support certain languages so I would like to init chrome using the --lang flag and start it with some other language. I searched the web and couldn't find any example to how it can be done.

My only lead was some article I saw and understood that I need to add to Protractor config file the "capabilities" section and there I can define the "args" property.

Then tried to tinker with it but no luck.

Any help will be most welcome.

Thanks,

Alon

Conviction answered 11/11, 2014 at 19:3 Comment(0)
C
1

As it turns out - the answer was in the docs all along. This is how you do it for chrome and i guess it similar for other browsers: inside the protractor.conf.js (for Spanish):

capabilities: {
        browserName: 'chrome',
            version: '',
            platform: 'ANY',
            'chromeOptions': {
                'args': ['lang=es-ES']}
    }
Conviction answered 16/11, 2014 at 11:18 Comment(0)
B
13

How to set Browser language and/or Accept-Language header

exports.config = {
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      // How to set browser language (menus & so on)
      args: [ 'lang=fr-FR' ],
      // How to set Accept-Language header
      prefs: {
        intl: { accept_languages: "fr-FR" },
      },
    },
  },
};

More examples:

intl: { accept_languages: "es-AR" }
intl: { accept_languages: "de-DE,de" }
Brooklynese answered 11/11, 2014 at 20:31 Comment(6)
Thanks, but how you go about it in protractor - i can't see in the config file documentation anything resembling this.Conviction
I pasted you my Protractor config. That's Protractor.Brooklynese
sadly - no :(. are you sure that we are talking about the same issue here?i want the browser menus to be in the language i choose in the flag so if i choose es i want to see all menus in spanish.Conviction
You're right, my config only addresses setting the accept-lang http header :( will leave it here in case somebody finds it useful.Brooklynese
How would you do this in Firefox? Is there a way to change the args in it, or would you have to use a separate binary for language specific tests?Observatory
My app uses window.navigator.language to determine UI language. Setting prefs.intl.accept_langauges enables me to affect this value. (Which surprises me, because I had understood that window.navigator.language is not controlled by the Accept-Language header but by browser UI settings.) YMMV.Defamatory
C
1

As it turns out - the answer was in the docs all along. This is how you do it for chrome and i guess it similar for other browsers: inside the protractor.conf.js (for Spanish):

capabilities: {
        browserName: 'chrome',
            version: '',
            platform: 'ANY',
            'chromeOptions': {
                'args': ['lang=es-ES']}
    }
Conviction answered 16/11, 2014 at 11:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.