0
votes

Scenario:

I have cypress tests that we run on multiple environments( more than 8), each environment with a separate domain, so we have configured all the domains in cypress.json file under env, now I need to pass the domain dynamically, i.e, from command line and be able to pick it and run the tests on respective domain. but I'm not sure how I can grab that value passed in command line.

Note: I have tried process.env method but did not work.

Code looks like this :

Cypress.json

{
   "env": {
     "domain1": xyz.com,
    "domain2": abc.com,
    "domain3": 123.com
   }
}

package.json :

{
   scripts: {
     "test": "npm run cypress open --env domian= $1 
    }
}

$1 is suppose to get me the command line argument" From my files under integration folder, Cypress.env(Cypress.env().domain) will/should fetch me the right domain.

However I'm receiving $1 as domain value.

Please help.

1
It seems like perhaps you forgot the closing quote after $1 in package.json?Timtech
Also, you had misspelled the env variable - "domian" instead of "domain"Dhamo
Thanks for your comments, however those two were just typo's while typing here.Rafiki

1 Answers

0
votes

Can you share how $1 is supposed to reference the env file? I don't understand that part.

In the meantime, here is an alternative answer to your problem. (just tested it out)

You can write several test scripts which each provide a different domain address.

{
   scripts: {
     "test1": "npm run cypress open --env domian=xyz.com",
     "test2": "npm run cypress open --env domian=abc.com",
     "test3": "npm run cypress open --env domian=123.com"
   }
}