How to overwrite baseUrl via commandline when using a config file that extends cypress.json? #16367
-
In my usecase I use the cypress.json config, and extends it in separate cypress-e2e.json and cypress-smoke.json to have different baseUrls for different environments. But sometimes however I want to run tests on another environment, i.e. on another baseUrl. Preferably I want to run that test from CI with the command argument "CYPRESS_BASE_URL=https://example.com cypress run... etc", but it occurs to me that the baseUrl isn't overwritten by my command line options as long as I have the cypress.json extended in one of my other config files. Is there a workaround to have the baseUrl overwritten while using the --config-file option in combination with the extends feature? In my example the command that doesn't overwrite baseUrl is: ps. I also tried |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here's a neat trick. You can dynamically modify the config from // cypress/plugins/index.js
module.exports = (on, config) => {
return config
} So, you could do: // cypress/plugins/index.js
module.exports = (on, config) => {
return {
...config
baseUrl: process.env.CYPRESS_BASE_URL || config.baseUrl
}
} That would override the |
Beta Was this translation helpful? Give feedback.
Here's a neat trick. You can dynamically modify the config from
cypress/plugins/index.js
:So, you could do:
That would override the
baseUrl
dynamically from an environment variable. Sinceplugins/index.js
is just JS, you have lots of power and flexibility. You should be able to use some combination of code and config to accomplish what you want.