【问题标题】:Overriding config file with env variable in Cypress在 Cypress 中使用 env 变量覆盖配置文件
【发布时间】:2020-10-27 21:09:35
【问题描述】:

我使用此链接作为将配置传递给我的 cypress 测试的参考:https://docs.cypress.io/api/plugins/configuration-api.html#Switch-between-multiple-configuration-files

我的示例配置文件如下所示:

 {
  "env": {
    "country": "US",
    "testenv": "staging",
    "US": {
     "baseUrl" : "somevalue"
    }
}

现在我想从命令行覆盖国家/地区值,我尝试使用

cypress open --env country="Germany"

但它仍然没有获取命令行中传递的值,并且仍然从配置文件中获取值。非常感谢您提供任何帮助!

【问题讨论】:

  • 您能否更新您的问题以显示您用于启动 cypress 并覆盖这些 env 值的完整 CLI 命令?
  • 完成。感谢您的编辑。

标签: javascript automated-tests integration-testing cypress


【解决方案1】:

不确定您的情况会怎样。这是npx cypress open时解决的设置@

现在当我使用$ npx cypress open --env country=Canada 运行时,这里是已解决的设置选项卡

【讨论】:

  • 就我而言,我按照指南中的建议通过插件传递文件,如下所示:module.exports = (on, config) => { // accept a configFile value or use development by default const file = config.env.configFile || "staging"; return getConfigurationByFile(file);function getConfigurationByFile(file) { const pathToConfigFile = path.resolve(".", "cypress/config", `${file}.json`); return fs.readJson(pathToConfigFile); } - 出于某种原因,它始终默认为配置文件中的值。我现在就试试你的方法。谢谢!
【解决方案2】:

我遇到了同样的问题并使用以下方法解决了它:

我正在使用以下命令:

npm run dev -- --config video=false

这被节点转换为以下:

cypress open -C config.json "--config" "video=false"

这仅在我的config.json 中没有视频标志时有效。所以我不能从我想覆盖的参数的默认值开始。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    相关资源
    最近更新 更多