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

Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110
Alon1980
  • 1,225
  • 1
  • 16
  • 30

2 Answers2

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" }
Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110
  • Thanks, but how you go about it in protractor - i can't see in the config file documentation anything resembling this. – Alon1980 Nov 12 '14 at 07:38
  • I pasted you my Protractor config. That's Protractor. – Leo Gallucci Nov 12 '14 at 13:43
  • 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. – Alon1980 Nov 13 '14 at 08:36
  • You're right, my config only addresses setting the accept-lang http header :( will leave it here in case somebody finds it useful. – Leo Gallucci Nov 13 '14 at 11:54
  • 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? – Peter Poliwoda Jan 18 '17 at 10:48
  • 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. – Arild Sep 14 '18 at 08:48
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']}
    }
Alon1980
  • 1,225
  • 1
  • 16
  • 30