moontemplar212
moontemplar212

Reputation: 13

How do I pass Cypress CLI arguments in the --env with a space?

I run Cypress from the command line as:

npx cypress open --env team=XXXX --config-file my_file.json

where my_file.json is my config file and contains:

env: {
    "team": ""
}

I know that when I pass a value via CLI with no space in it the Cypress runner will show that value in the configuration tab. How do I pass a value such as to team like:

--env team=XXXX XXXX

I have tried using "" and '' around the argument already and they have not worked. Thank you.

Upvotes: 1

Views: 5037

Answers (2)

joselog
joselog

Reputation: 26

I'm going to leave this comment here, in case someone else is looking for a solution.

this is what I did, and it worked for me.

in the terminal i'm doing:

npm run chat_true -- --env type="dev test"

note the "--" before --env

that's the only way I found to overwrite my env value, set in the package.json file like:

"chat_true": "cypress open --env type=live",

I don't need a space in the middle of the value, so I'm not using a quote surrounding the value, but I just tried it and it worked.

I'm three months late :D

Upvotes: 1

natn2323
natn2323

Reputation: 2061

From the documentation, it says "Pass several variables using commas and no spaces". So, off the bat, it sounds like what you're trying to do isn't possible. However, it may be worth a shot to try a different method. In particular, from this screenshot from the link I provided,

snippet

you can see that the last approach passes a JSON object. Perhaps, if for some reason Cypress parses this JSON object differently, you can try

cypress run --env team='{"key": "XXXX XXXX"}'

Alternatively, you could also have multiple Cypress configuration files, each with the relevant team value. However, if you have multiple team values, this simple approach doesn't scale particularly well.

Upvotes: 2

Related Questions