问题
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:
- Navigate to some "locale" page version (example.com/en/).
- 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'))
- Try to add your own Accept-Language header to your request.
- 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