TL;博士:
我正在尝试覆盖 baseUrl
来自 cypress.json
的值使用我的 cypress.env.json
文件,但我似乎无法弄清楚如何。有没有办法做到这一点?
背景
设置环境变量 在 cypress.json
文件,然后在 cypress.env.json
中覆盖它们为 easy as pie .在 cypress.json
:
{
"env": {
"someVariable": "originalValue"
}
}
... 并在
cypress.env.json
:{
"someVariable": "newValue"
}
关于配置变量 , 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.
但是,如果我尝试设置
baseUrl
来自 cypress.json
...{
"baseUrl": "http://example.com/setFromCypress.json",
"env": {
"someVariable": "originalValue"
}
}
... 并在
cypress.env.json
中覆盖它...{
"baseUrl": "http://example.com/setFromCypress.env.json",
"someVariable": "newValue"
}
... 然后
someVariable
被覆盖,但现有的 baseUrl
保持不变(baseUrl
出现在放置在 env
键处的对象内):设置
baseUrl
时没有问题在 cypress.json
然后在命令行中使用 CYPRESS_BASE_URL
覆盖它:$ export CYPRESS_BASE_URL=http://example.com/setFromCommandLine
那么,原
baseUrl
被覆盖:总结一下:我是在文档中遗漏了什么,还是在文档中遗漏了什么?
最佳答案
一个简单的解决方法:在 plugins/index.js 中做
module.exports = (on, config) => {
if(config.hasOwnProperty('env') && config.env.hasOwnProperty('baseUrl')){
config.baseUrl = config.env.baseUrl;
}
return config
}
关于javascript - 覆盖来自 cypress.env.json 的配置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47262338/