如何使用 Playwright 更改默认语言 Chromium/Firefox?

Con*_*oid 9 cross-browser selenium-chromedriver codeceptjs geckodriver playwright

我\xe2\x80\x99一直在尝试将浏览器Chromium和Firefox的默认语言(在使用CodeceptJS + Playwright作为运行器并行运行的自动化测试中)更改为法语,但没有成功。在Chromium中,我\xe2\x80\x99ve尝试使用args --lang但没有成功,并且我\xe2\x80\x99ve也尝试使用prefs:intl.accept_languages。在 Firefox 中,我尝试使用 firefoxUserPrefs。到目前为止,没有任何效果。\n有人知道如何更改使用 playwright 启动的浏览器中的默认语言吗?

\n

CodeceptJS 版本 3.0.6

\n

剧作家版本1.10.0

\n

Chrome 版本 90.0.4430.0

\n

火狐版本 87.0b10

\n

codecept.conf.js - 完整打印屏幕\n codecept.conf.js

\n
Playwright: {\n  url: process.env.baseUrl || DEFAULT_HOST,\n  show: true,\n  browser: \'chromium\',\n  waitForAction: 250,\n  waitForNavigation: \'networkidle0\',\n  chromium: {       \n    channel: process.env.BROWSER,\n    args: [\'--lang=fr-CA\'],\n    prefs: {\n      \'intl.accept_languages\': \'fr-CA\',\n    },\n    firefoxUserPrefs: {\n      \'intl.accept_languages\': \'fr-CA, fr\',\n    },\n  },\n}, \n
Run Code Online (Sandbox Code Playgroud)\n

har*_*ded 4

browser.NewContext有一个名为 的选项locale。您可以使用该选项来更改语言。

  • 这只是设置了 extraHTTPHeaders 所以我不明白这是一个解决方案。 (2认同)