1

I run my tests using the below synbtax. The issue i see is my organization is has extensions that block chrome headed tests from running. The tests run smooth headless using chrome but get blocked when they run headed using chrome. I am wondering if there is a way to run chrome headed using incognito.

npx cypress run --browser chrome --headed

Automation89
  • 31
  • 1
  • 8

2 Answers2

2

Within the cypress\plugins\index.js file put this code:

module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
        if (browser.family === 'chromium' && browser.name !== 'electron') {
            launchOptions.args.push("--incognito");                
            return launchOptions
        }

        if (browser.name === 'electron') {                
            launchOptions.preferences.incognito = true               
            return launchOptions
        }
    })    
}
Vict01
  • 300
  • 1
  • 10
1

I have used cypress and I ran my cypress test runner in incognito mode. All you need to do is to provide the below code in your index.js file inside the plugins folder of cypress.

 module.exports = (on, config) => {
 
   on("before:browser:launch", (browser, launchOptions) => {
     console.log(launchOptions.args);
     if (browser.name === "chrome") {
       launchOptions.args.push("--incognito");
     }
     return launchOptions;
   });
 };

Reference for the same: https://docs.cypress.io/guides/references/migration-guide#Plugin-Event-before-browser-launch

greybeard
  • 2,249
  • 8
  • 30
  • 66