Cypress: Cannot specify the default running browser in cypress.json configuration file

Created on 4 Mar 2020  路  3Comments  路  Source: cypress-io/cypress

Current behavior:

The only way to specify the browser to use is via CLI options cypress --browser chrome --headless for example. There is no field in the configuration that allows users to specify the browser and headless mode.

Desired behavior:

To be able to specify the browser and headless mode in the JSON configuration file, for example

{
  "browser": "chrome",
  "headless": true
}

Then running cypress directly via cypress run would use chrome headless.

Versions

Cypress 4.1.0
Debian Buster
(from cypress/included docker image)

proposal 馃挕 feature

Most helpful comment

This is just the only option that cannot be specified in the cypress.json file, if you look at test specs, they can be specified in cypress.json so you don't need to pass it to every command you run. In the same way, it is puzzling that one cannot specify the default browser to run the tests in cypress.json. For just the sake of consistency, one would argue all options should be able to be configured in the configuration file as well as being overridden in the CLI.

In our specific use case, we configured our package.json file to run cypress tests with slightly different options/environment variables by having npm run test and npm run test:ci, npm run test:extra etc. In order to use Chrome headless, we'll have to copy & paste --browser chrome --headless to all of them (or using npm env vars which aren't very readable). Today, all other options are specified in cypress.json and we could just override some in the command if we want to have different behaviours. We really would like to also have the browser specified in cypress.json to have all the options in a single file.

All 3 comments

@librehat Can you explain a bit more about why you need this feature?

This would make the browser choice static per project.

  • For cypress run, it would seemingly always attempt to run the tests in the browser of choice.
  • For cypress open, it would choose this browser by default in the UI.

And then the CLI option would override this?

I'd just like to understand more about why this is necessary for your project in particular so we can approach this at the problem you are having, as opposed to this specific proposed solution.

This is just the only option that cannot be specified in the cypress.json file, if you look at test specs, they can be specified in cypress.json so you don't need to pass it to every command you run. In the same way, it is puzzling that one cannot specify the default browser to run the tests in cypress.json. For just the sake of consistency, one would argue all options should be able to be configured in the configuration file as well as being overridden in the CLI.

In our specific use case, we configured our package.json file to run cypress tests with slightly different options/environment variables by having npm run test and npm run test:ci, npm run test:extra etc. In order to use Chrome headless, we'll have to copy & paste --browser chrome --headless to all of them (or using npm env vars which aren't very readable). Today, all other options are specified in cypress.json and we could just override some in the command if we want to have different behaviours. We really would like to also have the browser specified in cypress.json to have all the options in a single file.

Agreed. We use the netlify cypress plugin and because we cannot set it in cypress.json, then all tests are run via Electron.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igorpavlov picture igorpavlov  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

szabyg picture szabyg  路  3Comments

scottcrowe picture scottcrowe  路  3Comments

carloscheddar picture carloscheddar  路  3Comments