Cypress not launching in incognito mode , Version 13.3.3

162 views Asked by At

I am using the below code, and saving it index.js file or even a config.js file but Cypress not opening in incognito in Google Chrome or any other browsers.

Method# 1:

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

Method#2:

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
        }
    })    
}

Both two methods I have applied but no one is working !

1

There are 1 answers

0
TesterDick On

I'm using launch options for other args. When I push --incognito, the browser appears in ingonito mode (icon top-right of browser window).

The browser test I'm using is browser.family === 'chromium'.

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

I don't think Electron has incognito mode, and I tried -private for Firefox but couldn't get it to work - well, it seems to be in incognito mode, but complains that an extension is missing.