【问题标题】:Run part of the test suite only in specific environment in Cypress仅在赛普拉斯的特定环境中运行部分测试套件
【发布时间】:2021-04-01 10:41:18
【问题描述】:

我有一个在 4 个环境中运行的测试套件:localstagingproduction,让我们说custom 使用env 变量。我想让一些测试只在production 上运行,一些测试只在staging 上运行,如何标记特定的describe/test/test 文件才能做到这一点?

【问题讨论】:

    标签: javascript testing automated-tests cypress


    【解决方案1】:

    在赛普拉斯项目的根目录中,创建一个cypress.json 并添加您的生产网址。例如:

    {
      "baseUrl": `https://www.production.com`,
    }
    

    现在,如果您在运行测试cypress run 时不传递任何环境变量,您的测试将针对生产运行。

    您还可以设置不同的 baseUrl 来运行。例如:

    CYPRESS_BASE_URL=https://www.development.com cypress run
    

    然后您可以在测试中检索 baseUrl:

    const isProd = Cypress.config().baseUrl === "https://www.production.com";
    const isDev = Cypress.config().baseUrl === "https://www.development.com";
    const isStaging = Cypress.config().baseUrl === "https://www.staging.com";
    const isCustom = Cypress.config().baseUrl === "https://www.custom.com";
    

    根据您的测试设置,有不同的方法可以从这里构建它。根据上述变量将skip 参数传递给您的测试,或者设置您的测试运行程序以按环境跳过/运行整批测试:

    function runTests() {
        if (isDev) {
            runDevTests()
        }
        if (isStaging) {
            runStagingTests()
        }
        if (isProd) {
            runStagingTests()
        }
        if (isCustom) {
            runCustomTests()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 2023-02-10
      • 2021-06-13
      • 2019-07-29
      • 2023-02-14
      • 2020-10-26
      • 1970-01-01
      相关资源
      最近更新 更多