TestCafe & chrome:headless : how to force the browser language (locale)

谁说我不能喝 提交于 2021-01-29 03:13:32

问题


I have write a few browser test who run with TestCafe, chrome:headless. The test are launched by commandline, from a server that I don't want to change the default language.

My website is multi-language. I want to be change the language of the test, without having to impact the language of the server/computer each time. How can I do that?

I launch the tests with this command line:

npx testcafe chrome:headless src/scenarios/**/*.test.ts

回答1:


It all depends on your "multi-language" implementation:

  1. Navigate to some "locale" page version (example.com/en/).
  2. Start your tests from a landing page and then navigate to the specific "locale" version:
await t
    .click(Selector('#choose-lang-combo')
    .click(Selector('#en-lang'))
  1. Try to add your own Accept-Language header to your request.
  2. Use a custom user profile:

For example, to create a shortcut that launches Google Chrome in Spanish (es), you might create a shortcut named chrome-es that has the following target:path_to_chrome.exe --lang=es --user-data-dir=c:\chrome-profile-es



来源:https://stackoverflow.com/questions/58076377/testcafe-chromeheadless-how-to-force-the-browser-language-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!