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.
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.
Cypress 4.1.0
Debian Buster
(from cypress/included
docker image)
@librehat Can you explain a bit more about why you need this feature?
This would make the browser choice static per project.
cypress run
, it would seemingly always attempt to run the tests in the browser of choice. 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.
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 incypress.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 incypress.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 runcypress
tests with slightly different options/environment variables by havingnpm run test
andnpm 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 incypress.json
and we could just override some in the command if we want to have different behaviours. We really would like to also have thebrowser
specified incypress.json
to have all the options in a single file.