1👍
It is more of a best practice to run spec files against a single environment one at a time. It is either you use an overriding cypress.env.json
or create 2 config files for each environment (test and prod for example) which will override env variables both set in cypress.env.json
and cypress.json
. https://docs.cypress.io/guides/guides/environment-variables.html#Option-2-cypress-env-json
However, if you want a quick and dirty solution to your issue above (I don’t suggest this), you can set your spec files with the below:
cypress.json
{
"env": {
"CONFIG": {
"id": "19285",
"address": "343..."
},
"CONFIG_PROD": {
"id": "19285",
"address": ""
}
}
}
spec_1.js
const config = Cypess.env("CONFIG")
spec_2.js
const config = Cypress.env("CONFIG_PROD")
or just simply put them under fixture files (which I believe is more appropriate for this case):
config.json
{
"test": {
"id": "19285",
"address": "343..."
},
"prod": {
"id": "19285",
"address": ""
}
}
spec_1.js
import {test, prod} from '../fixtures/config.json'
const address = test.address
const address_null = prod.address //If you would like to run this on another 'it' test
spec_1.js
import {prod} from '../fixtures/config.json'
const address_null = prod.address
Source:stackexchange.com