In our setup we are using Cypress v12.x with 2 different browsers:
- the chrome browser (we use this when running the cypress app interactively
yarn cypress open)
- the electron browser (is used when running the tests headless on CI
yarn cypress run)
We found that we need to configure both browsers separately
chrome
we use the Cypress Browser Launch API (https://docs.cypress.io/api/plugins/browser-launch-api#Changing-browser-preferences) to customize the chrome configuration.
// file cypress.config.js
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on("before:browser:launch", (browser, launchOptions) => {
if (browser.family === "chromium" && browser.name !== "electron") {
launchOptions.preferences.default.intl = {
accept_languages: "en-US,en",
selected_languages: "en-US,en",
};
return launchOptions;
}
});
},
},
});
electron
we use the environment variable ELECTRON_EXTRA_LAUNCH_ARGS (https://docs.cypress.io/api/plugins/browser-launch-api#Modify-Electron-app-switches) to pass extra args to the electron browser.
// file package.json
"scripts": {
"e2e:run": "ELECTRON_EXTRA_LAUNCH_ARGS=--lang=en yarn cypress run",
...
}
summary
with this configuration the browser is using the specified locale when using the cypress app and also when running the tests on our CI server