8

I’ve been trying without success to change default language of browsers Chromium and Firefox (inside automated tests that run in parallel using CodeceptJS + Playwright as runner) to french language. In Chromium, I’ve tried to use args --lang without success and I’ve also tried to use prefs: intl.accept_languages. In Firefox, I’ve tried to use firefoxUserPrefs. Untill now, nothing has worked. Does anybody know how to change default language in browser launched using playwright?

CodeceptJS version 3.0.6

Playwright version 1.10.0

Chrome version 90.0.4430.0

Firefox version 87.0b10

codecept.conf.js - full printscreen codecept.conf.js

Playwright: {
  url: process.env.baseUrl || DEFAULT_HOST,
  show: true,
  browser: 'chromium',
  waitForAction: 250,
  waitForNavigation: 'networkidle0',
  chromium: {       
    channel: process.env.BROWSER,
    args: ['--lang=fr-CA'],
    prefs: {
      'intl.accept_languages': 'fr-CA',
    },
    firefoxUserPrefs: {
      'intl.accept_languages': 'fr-CA, fr',
    },
  },
}, 
Roman Mkrtchian
  • 2,548
  • 1
  • 17
  • 24
Conta Android
  • 81
  • 1
  • 3

3 Answers3

4

browser.NewContext has an option called locale. You can use that option to change the language.

hardkoded
  • 18,915
  • 3
  • 52
  • 64
  • 2
    This just sets extraHTTPHeaders so I do not see how this is a solution. – Mecanik Feb 15 '22 at 09:09
  • Exactly what I needed. I suspect the site's geolocation was inaccurate, putting my IP in Mexico (and giving me Spanish) when really my IP is in California and I want English. Thanks! – rinogo Jun 28 '22 at 14:06
2

This might not have been available by the time of this question, but now there are emulation options for locale (and timezone) in Playwright (documentation here).

Can be specified both globally in config, per project, like this (in playwright.config.ts):

...
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        locale: 'fr-CA',
      },
    },
...

or per test, like this:

test.use({ 
  locale: 'sv-SE',
});

test('Lang test 1', async ({ page }) => {
  // Test code
});
maets
  • 750
  • 6
  • 18
0

There is bug in Playwright regarding not respecting locale settings: https://github.com/microsoft/playwright/issues/13919 https://github.com/microsoft/playwright/issues/18609

Vote with and comment to make this issue more visible for creators.

pbaranski
  • 22,778
  • 19
  • 100
  • 117