1

I'm trying to run tests with Cypress using electron browser, but the system language is changed according to the language of the browser. This is making the tests fail.

I've tried to override visit method as in the code below, but didn't work.

/ commands.js
Cypress.Commands.overwrite("visit", (originalVisit, url, options = {}) => {
  console.log('calling cy.visit')
  const opts = {
    onBeforeLoad: (win) => {
      Object.defineProperty(win.navigator, 'language', {
        value: 'pt-BR'
      })
    },
    onLoad: (win) => {
      console.log('onLoad')
    }
  }
  return originalVisit(url, opts)
})

My question is: Is there any way I can configure the browser to always start with a specific language?

1 Answers1

0

Try to modify your browser launch preferences. For your specific case, this piece of code could be useful:

on('before:browser:launch', (browser, launchOptions) => {
   if (browser.family === 'chromium') {
     launchOptions.preferences.default.intl = { accept_languages: 'pt-BR' };
     return launchOptions;
   }
});

https://docs.cypress.io/api/plugins/browser-launch-api.html#Modify-browser-launch-arguments-preferences-and-extensions

amolinaalvarez
  • 345
  • 2
  • 9