3

I am using this link as a reference to pass configuration to my cypress tests : https://docs.cypress.io/api/plugins/configuration-api.html#Switch-between-multiple-configuration-files

My sample config file looks like this:

 {
  "env": {
    "country": "US",
    "testenv": "staging",
    "US": {
     "baseUrl" : "somevalue"
    }
}

Now I want to override the country value from the command line, I tried using

cypress open --env country="Germany"

but it still doesn't pickup the value passed in command line and still takes the value from configuration file. Any help on this is much appreciated!

Vall
  • 3,926
  • 3
  • 14
  • 14

2 Answers2

2

Not sure what happens in your case. Here is the resolved settings when doing just npx cypress open

enter image description here

Now when I run with $ npx cypress open --env country=Canada here is the resolved settings tab

enter image description here

gleb bahmutov
  • 1,801
  • 15
  • 10
  • In my case, i am passing the file via the plugin as recommended in the guide like this: ```module.exports = (on, config) => { // accept a configFile value or use development by default const file = config.env.configFile || "staging"; return getConfigurationByFile(file);``` ```function getConfigurationByFile(file) { const pathToConfigFile = path.resolve(".", "cypress/config", `${file}.json`); return fs.readJson(pathToConfigFile); }``` - for some reason, it always defaults to the values in the config file. I will try your method now. Thank You! – Vall Oct 27 '20 at 22:22
0

I ran into same problem and resolved it using the following approach:

I am using following command:

npm run dev -- --config video=false

This gets converted into following by node:

cypress open -C config.json "--config" "video=false"

This ONLY works when I don't have the video flag present in my config.json. So I can't start with a default value for a parameter that I would like to override.

Syed Ali
  • 1,817
  • 2
  • 23
  • 44