Reputation: 1879
I trying to figure out how to read a config file provided by CLI parameter --config-file
Using this parameter as follows cypress open --config-file cypress/config/stage.json
Contents for stage.json
file is:
{
"auth_url": "https://example.com/",
"auth_username": "[email protected]",
"auth_password": "password"
}
However... using Cypress.env('...')
, values return undefined, as detected by the following expect
.
const authUsername = Cypress.env('auth_username');
const authPassword = Cypress.env('auth_password');
const authUrl = Cypress.env('auth_url');
expect(authUsername).to.be.a('string').not.empty;
expect(authPassword).to.be.a('string').not.empty;
expect(authUrl).to.be.a('string').not.empty;
What am I missing? Thank you, much appreciated.
Upvotes: 0
Views: 1389
Reputation: 1789
If you want to read the values from stage.json
config file, you need to use the command Cypress.config
instead of Cypress.env
:
// Use Cypress.config
{
"auth_url": "https://example.com/",
"auth_username": "[email protected]",
"auth_password": "password"
}
If you want to read with Cypress.env
command, within stage.json
you should declare as:
// Use Cypress.env
{
"env": {
"auth_url": "https://example.com/",
"auth_username": "[email protected]",
"auth_password": "password"
}
}
Upvotes: 2