TL;DR:
I am trying to override the baseUrl
value from cypress.json
using my cypress.env.json
file, but I can't seem to figure out how. Is there a way to do this?
Background
Setting environment variables in the cypress.json
file and later overriding them in cypress.env.json
is as easy as pie. In cypress.json
:
{
"env": {
"someVariable": "originalValue"
}
}
... and in cypress.env.json
:
{
"someVariable": "newValue"
}
Regarding configuration variables, the documentation states:
If your environment variables match a standard configuration key, then instead of setting an
environment variable
they will instead override the configuration value.
However, if I try setting baseUrl
from cypress.json
...
{
"baseUrl": ".json",
"env": {
"someVariable": "originalValue"
}
}
... and overriding it in cypress.env.json
...
{
"baseUrl": ".env.json",
"someVariable": "newValue"
}
... then someVariable
is overriden, but the existing baseUrl
remains unchanged (and a baseUrl
appears inside the object placed at the env
key):
I have no problem when setting baseUrl
in cypress.json
and later overriding it in the command line using CYPRESS_BASE_URL
:
$ export CYPRESS_BASE_URL=
Then, the original baseUrl
is overriden:
To summarize: Am I missing something in the documentation, or is something missing in the documentation?
TL;DR:
I am trying to override the baseUrl
value from cypress.json
using my cypress.env.json
file, but I can't seem to figure out how. Is there a way to do this?
Background
Setting environment variables in the cypress.json
file and later overriding them in cypress.env.json
is as easy as pie. In cypress.json
:
{
"env": {
"someVariable": "originalValue"
}
}
... and in cypress.env.json
:
{
"someVariable": "newValue"
}
Regarding configuration variables, the documentation states:
If your environment variables match a standard configuration key, then instead of setting an
environment variable
they will instead override the configuration value.
However, if I try setting baseUrl
from cypress.json
...
{
"baseUrl": "http://example.com/setFromCypress.json",
"env": {
"someVariable": "originalValue"
}
}
... and overriding it in cypress.env.json
...
{
"baseUrl": "http://example.com/setFromCypress.env.json",
"someVariable": "newValue"
}
... then someVariable
is overriden, but the existing baseUrl
remains unchanged (and a baseUrl
appears inside the object placed at the env
key):
I have no problem when setting baseUrl
in cypress.json
and later overriding it in the command line using CYPRESS_BASE_URL
:
$ export CYPRESS_BASE_URL=http://example.com/setFromCommandLine
Then, the original baseUrl
is overriden:
To summarize: Am I missing something in the documentation, or is something missing in the documentation?
Share Improve this question asked Nov 13, 2017 at 10:37 vagesvages 3481 gold badge6 silver badges14 bronze badges 4- 1 I think it's a bug.. would create an issue – dwelle Commented Nov 13, 2017 at 13:45
- Done: github.com/cypress-io/cypress/issues/909 – vages Commented Nov 14, 2017 at 14:32
- I think you can add that as an answer, @DanSwain. Just do so, and I'll give you the checkmark. ;) – vages Commented Nov 16, 2017 at 11:38
- Done @vages. Thank you. – Dan Swain Commented Nov 19, 2017 at 19:57
2 Answers
Reset to default 11A simple workaround: in plugins/index.js do
module.exports = (on, config) => {
if(config.hasOwnProperty('env') && config.env.hasOwnProperty('baseUrl')){
config.baseUrl = config.env.baseUrl;
}
return config
}
After the above post, it was explained in the related github issue that this is not considered a bug. Variables from cypress.env.json
are loaded into the environmentVariables
variable within the overall config (despite what the current documentation would lead you to believe). The overall config file is cypress.json. In the github issue, I've provided backup concerning why the current explanation is confusing.