Overriding baseUrl from cypress.env.json
See original GitHub issueCurrent behavior:
Setting baseUrl
in cypress.env.json
leads to the key baseUrl
being created inside env
(the environment variables), not in the existing baseUrl
being overridden at the configuration variable level.
Desired behavior:
baseUrl
should be overridden, the behavior matching that stated in the section “Overriding Configuration” in the environment variables documentation. (Note: Overriding via the command line works as expected.)
How to reproduce/Test Code:
cypress.json:
{
"baseUrl": "http://example.com/setFromCypress.json",
"env": {
"someVariable": "originalValue"
}
}
cypress.env.json:
{
"baseUrl": "http://example.com/setFromCypress.env.json",
"someVariable": "newValue"
}
Screenshot of the resulting configuration:
Additional Info (images, stack traces, etc)
This issue was initially posted and phrased as a question on StackOverflow: https://stackoverflow.com/q/47262338/1858138
- Operating System: Mac OS 10.13.1 (17B48)
- Cypress Version: Cypress package version: 1.0.3
- Browser Version: Chrome 60
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:38 (14 by maintainers)
Top Results From Across the Web
Environment Variables | Cypress Documentation
You can create your own cypress.env.json file that Cypress will automatically check. Values in here will overwrite conflicting environment variables in your ...
Read more >Override Cypress.config().baseUrl with environment variable ...
env file. I can't set it directly in the cypress.json file. And when I try to use cy.visit(process.
Read more >Switch between environments in Cypress - Filip Hric
The easiest way to switch environments is to simply rewrite your cypress.json file and set baseUrl to a different value each time you...
Read more >cypress-io/cypress - Gitter
baseUrl return config }. _. in plugins/index.js. I know, baseUrl isn't really an envvar, it's right, so it shouldn't be in cypress.env.json in...
Read more >Configure Cypress Tests to Run on Multiple Environments
Method 1. Configuring Cypress To Run On Different Environments Using baseUrl in cypress.json · Step 1: Navigate to The cypress.json File Located ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From docs, I got the same idea as OP. This part in particular:
Plus, the cypress runner configuartion “settings” tab doesn’t do a good job in explaining that even though
env
has higher precedence than e.g.cypress.json
ordefault
, it doesn’t override it at all…@brian-mann I think that the concept of cypress.env.json was a good one but that perhaps expanding it would be more than adequate at this point (as opposed to creating a new plugin event right now). Changing the names/function of the files as follows might be a good approach.
Change cypress.json to cypress.conf.json
Have a cypress.conf.local.json file whose key structure can match and override cypress.conf.json as @Vages suggests and which would not be checked into source control
This structure would allow you to keep the cypress.env.json for backward compatibility at this point, but it could be deprecated and then eventually eliminated (same for cypress.json).