简体   繁体   中英

Overriding config file with env variable in Cypress

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!

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

在此处输入图片说明

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

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM