I want to be able to run my tests in terminal, but all my tests fail due to Cypress using Electron as the default browser and I want it to utilize Chrome, but without having to specify it in the command line.
I know I can use the command npx cypress run --browser chrome to tell Cypress to use Chrome instead. However, it opens the browser AND runs it in command line.
Ideally it would only require me to run npx cypress run and this would only run in the command line using Chrome.
Is there a way to set the default browser to Chrome instead of Electron so I wouldn't need to specify which browser to use?
Is there something to add to the package.json file to set the default browser to Chrome or a line to inject somewhere? I checked the docs and I couldn't really find anything other than the --browser command.
Here is the link to the open issue on their github regarding a headless chrome and also to change the default for cypress run
Support chrome headless and change defaults for cypress run
Sorry for the terrible scribbles...I am under an NDA so had to go back and scratch out all the path names for my project as well as my last name.

Cypress 3.8.1+ allows you to pass --headless to cypress run to make Chrome invisible on any operating system by using Chrome headless:
cypress run --headless --browser chrome
There is not currently a way to hide Chrome in
runmode on macOS or Windows.We'd like to support it, but we'd have to find some kind of workaround for
xvfbnot being available. We can't usegoogle-chrome --headlesseither because it won't allow us to install the Cypress extension.
The advice below will only work for Linux.
npx cypress run --browser chromeis the correct way to do what you're trying to do.If you are on Linux, you can make it run Chrome in a virtual framebuffer (so it will be hidden from you) by blanking out the
DISPLAYenv variable:
DISPLAY= npx cypress run --browser chrome
Technical explanation:
- Cypress does not support running in "headless Chrome" - headless Chrome was not around when Cypress was first written
- So, when Cypress is running in Chrome in CI, it uses
xvfbto create an X virtual framebuffer, then it uses theDISPLAYvariable to tell Chrome to run in thexvfb- However, if you have
DISPLAYset (by default, it is set on Linux if you have a display manager), it will use thatDISPLAYinstead - this is why it appears even though you're doingcypress run.- Adding
DISPLAY=before the command nulls outDISPLAY, which means that Cypress will spawnxvfband run it inside of there instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With