Overriding config file with env variable in Cypress

Viewed 1206

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!

2 Answers

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

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.

Related