【问题标题】:How to run cypress tests with tags in nrwl nx workspace如何在 nrwl nx 工作区中使用标签运行 cypress 测试
【发布时间】:2022-08-14 16:40:40
【问题描述】:

我在 nrwl nx 工作区工作,我在其中设置了一个 cypress BDD 黄瓜项目。 我需要使用 nrwl 基于标签运行 cypress 测试。

通常我会使用 cypress-tags 命令来做同样的事情: 例如:\"cypress run --env TAGS=\'@smoke\' --browser chrome\"

我将相同的逻辑应用于 nx 命令。 例如:nx e2e myProject-e2e --tags=@reg

但是 nx 项目正在识别 cypress 中的所有测试用例,它没有考虑标记为“@reg”的测试用例

如果 nrwl 中有规定可以根据标签运行 cypress 测试,有人可以指导我吗

    标签: typescript cypress pipeline nrwl-nx


    【解决方案1】:

    我遇到了同样的问题,并通过使用来自NX configuration 的 ENV 对象得到了解决方法:

    这样,我在project.json 配置文件中添加了标签,在我的例子中,用于运行烟雾测试和基于标签过滤的回归测试:

    "smoke": {
      "executor": "@nrwl/cypress:cypress",
      "options": {
        "cypressConfig": "apps/explore-e2e/cypress.json",
        "baseUrl": "<BASE_URL>",
        "env": {
          "TAGS": "@smoke"
        }
      },
      "configurations": {
        "staging": {
          "baseUrl": "<STG_URL>"
        },
        "production": {
          "baseUrl": "<PROD_URL>"
        }
      }
    },
    "regression": {
      "executor": "@nrwl/cypress:cypress",
      "options": {
        "cypressConfig": "apps/explore-e2e/cypress.json",
        "baseUrl": "<BASE_URL>",
        "env": {
          "TAGS": "@regression"
        }
      },
      "configurations": {
        "staging": {
          "baseUrl": "<STG_URL>"
        },
        "production": {
          "baseUrl": "<PROD_URL>"
        }
      }
    }
    

    有了这个,您现在可以开始标记您的场景并运行它:

    nx e2e myProject-e2e:smoke --TAGS=@smoke
    

    (就我而言,我使用的是:yarn nx run

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 2019-06-30
      • 2020-02-10
      • 2019-01-07
      • 2022-08-13
      • 2021-05-13
      • 2019-03-16
      • 2020-06-02
      • 2018-07-28
      相关资源
      最近更新 更多