-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot specify the default running browser in cypress configuration file #6646
Comments
@librehat Can you explain a bit more about why you need this feature? This would make the browser choice static per project.
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 In our specific use case, we configured our |
Agreed. We use the netlify cypress plugin and because we cannot set it in cypress.json, then all tests are run via Electron. |
We have these config options in out |
@sesam This configuration option was never available through Cypress by itself. We likely added stricter checks around configuration values at some point which is why you see a warning about it. |
I would also like to see this implemented. The app I test is only supported in Chrome and I have about 10 different config files. |
I have nothing to add, but this would really help me out as well. |
Good to have it in cypress.json |
I have similar issue , can some one give me solution , I need torun test aginst multple envn in chrome browser
running npx cypress run --headed --browser chrome is successful Also , I have cy.lighthouse in my test which is supported ony in Chrome |
Under Cypress 9.2, Electron hangs and crashes constantly in my CI environment -- it's yet another bug related to screenshots and/or video recording and I haven't been able to root-cause it, just to isolate it. If I use Chrome headless in CI, I can avoid the crash. Ultimately I want to switch back to Electron, but given that I need to use Chrome as a workaround, I'd strongly prefer if all Cypress modes were to use Chrome as the default browser -- My use case will (hopefully) wane in importance once Electron becomes stable again, but I can see how others would have a more consistent need to run tests in a specific browser, e.g. if their test suite relies on browser-specific extensions or technologies. It's a minor pain and a footgun to force developers to choose the right browser. |
My use case is specific. I am testing an Ionic app, which will always run on chrome and depend on specific Chrome behavior. All test work as expected with Using It would be easier to set that (and the version) in the json config so developers do not have to wonder why some tests fail when running locally. |
This functionality exists today in Cypress, via plugins. You can modify Docs: https://docs.cypress.io/api/plugins/configuration-api#Customize-available-browsers For the use case of only allowing Chrome (@distante @xeger and several others) you can do something like this: // cypress/plugins/index.js
module.exports = (on, config) => {
// inside config.browsers array each object has information like
// {
// name: 'chrome',
// family: 'chromium',
// channel: 'canary',
// displayName: 'Canary',
// version: '80.0.3966.0',
// path:
// '/Applications/Canary.app/Contents/MacOS/Canary',
// majorVersion: 80
// }
return {
browsers: config.browsers.filter((b) => b.name === 'chrome'),
}
} Closing since this is already functionality available in Cypress and we do not anticipate adding a config option for it at this time. |
@flotwig That doesn't work. When I filter
Is there no other way to specify the default browser other than the |
I ran into a similar issue and resolved it by changing the return {
...config,
browsers: config.browsers.filter((b) => b.family === "chromium")
} This exposes both "chrome" and "electron" in the browsers list. |
@mikedidthis But I'm not trying to filter the list for |
same here. somehow it puzzles me why the default browser cannot be set in cypress.json. |
Reopening as this is a feature request that isn't adequately available in Cypress today still. |
While I really do love the sleek new UI in Cypress 10, the increase in the number of clicks required between running Prior to Cypress 10, I would run
The best way to avoid this is to add CLI args So, in the interest of quality of life, I'd love to have an option to specify these in |
Not being able to choose a browser for a CLI run doesn't make any sense. Seems to be a basic necessity for a tool that can run tests in various browsers. |
@flotwig did you even try your suggestion before closing the issue? |
Ah, would really make sense to have it on the |
I used to run cypress in the CLI with the default Electron. But then I discovered that some tests were failing in Electron, but passed in Chrome and Firefox. In reviewing the failures, I could not find anything wrong. Since then, I've specified chrome in every test. Electron is useless to me. This option should definitely be in the config file. As of now, there's a default -- put in by Cypress -- that I can't change, and that makes it a pain to use. |
I am part of a company where 99% of users (+30 million) use Chrome and by default I would like to leave this information fixed, because in Electron there are errors in which Chrome does not show any errors. I would like an easy implementation like: In the cypress.config.js file
|
I found a workaround using runner. Finally! In the root of the project, create a .js file of any name. This will be your runner. In the file, load Cypress and in cypress.run define the chosen browser.
To test it, just run In cypress.run it is possible to define several things, such as specs, browser, configs... Hope this helps |
An additional temporary way to specify a default browser with // scripts/runCypress.mjs
import { execSync } from 'node:child_process'
import process from 'node:process'
try {
// Extracting parent shell arguments and preventing JSON ones from subshell parsing
const args = process.argv
.slice(2)
.map(arg => (arg.startsWith('{') ? `'${arg}'` : arg))
.join(' ')
// Specify the desired fixed flags here, e.g., `--e2e` or `--browser electron`
execSync(`cypress ${args} --browser chrome`, { stdio: 'inherit' })
} catch (error) {
process.stderr.write(`Error: ${error.message}\n`)
process.exitCode = 1
} Then in {
...
"scripts": {
...
"cypress": "node scripts/runCypress.mjs",
}
} Now, both |
➕ 1️⃣ from me and my team on this as well. It would be nice to have something that was the default that could be overridden in specific cases. 99% of the time our users are using chrome and we want this to be the default instead of electron. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
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
Then running cypress directly via
cypress run
would use chrome headless.Versions
Cypress 4.1.0
Debian Buster
(from
cypress/included
docker image)The text was updated successfully, but these errors were encountered: