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?
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 variablethey 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?
You can pass in environment variables as options when using the CLI tool. Values here will overwrite all other conflicting environment variables. You can use the --env argument for cypress run. Multiple values must be separated by a comma, not a space.
Windows 8 and Windows 10In the User variables section, click New to open the New User Variable dialog box. Enter the name of the variable and its value, and click OK. The variable is added to the User variables section of the Environment Variables dialog box. Click OK in the Environment Variables dialog box.
If you want to apply different settings, you need to write a complete second configuration file and use it via the --config-file <filename> command line argument. Then the continuous integration server would use the command npx cypress run --config-file staging. json to use the later configuration file.
You can use the configuration API and do something like this on your plugins file. Set config. env = process. env which will set your entire node env for Cypress .
A 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With