0

I am trying to run a test case in Cypress in a headed Edge browser.

How do I set-up this test to run Edge in Incognito/Private mode?

I've found an example using Chrome: How to run Cypress headed tests using Chrome Incognito

but not Edge.

The way start/run the test is with the command: npx cypress run.

Once Cypress open i click on the Edge Option, then it opens the Edge in headed mode.

msuzuki
  • 105
  • 2
  • 15

1 Answers1

1

It's more or less the same, but the flag you need is --inprivate
The following should work:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('before:browser:launch', (browser = {}, launchOptions) => {
        // `args` is an array of all the arguments that will
        // be passed to browsers when it launches
        console.log(launchOptions.args) // print all current args

        if (browser.name === 'edge') {
          // open in incognito
          launchOptions.args.push('--inprivate')
        }

        // whatever you return here becomes the launchOptions
        return launchOptions
      })
    },
  },
})
WSD
  • 3,243
  • 26
  • 38
  • I tried your option and the others (https://stackoverflow.com/questions/68896471/how-to-run-cypress-headed-tests-using-chrome-incognito) but the browser does not open in incognito/private. I may be doing something wrong, I added the suggested config inside cypress/plugins/index.js, and still no success. – msuzuki May 05 '23 at 20:06
  • 1
    I kind of mix-and-match your solution. The corporation blocks Edge Private, but not Chrome. With your template with Chrome in the cypress.config it worked. – msuzuki May 05 '23 at 20:29
  • Sorry for the silly question, but I need to be sure, are you trying to open the Browser in Incognito/Private or headless? – WSD May 05 '23 at 20:29
  • Browser in Incognito/Private – msuzuki May 06 '23 at 13:18