在命令行上使用 ng e2e 指定 grepTags

问题描述 投票:0回答:2

在我们的 Angular 项目中,我们使用 cypress-grep 包来过滤测试。

我们有一个测试模块,它指定 grepTags,然后引用一些现有的测试,大致如下:

import cypressGrep from '@cypress/grep'

Cypress.env('grepTags', '@smoke');
cypressGrep();

context('cypress/e2e/Test1.cy.ts', () =>
  require('cypress/e2e/Test1.cy.ts'))
context('cypress/e2e/Test2.cy.ts', () =>
  require('cypress/e2e/Test2.cy.ts'))
context('cypress/e2e/Test3.cy.ts', () =>
  require('cypress/e2e/Test3.cy.ts'))

我们使用

ng e2e
命令开始测试,使用 --spec 参数选择测试文件。 例如:

ng e2e --spec **/smoketest/*.cy.ts

作为替代方案,我认为最好在命令行上从外部指定标签,例如

set grepTags=@smoke
ng e2e

最终我想在构建管道中指定标签(我们正在使用 Azure Devops)。

到目前为止我还没有找到一种方法来完成这项工作。
可以吗?

angular cypress e2e-testing cypress-grep
2个回答
0
投票
  1. 您错误地设置了 grepTags。您需要将标签传递到
    describe
    /
    context
    /
    it
    块,而不是设置 Cypress 环境变量。

您可以使用任何方式修改环境值 grep 和 grepTags,除了运行时

Cypress.env('grep')
(因为在运行时为时已晚)。 (来源:赛普拉斯)

相反,您可以像这样传递标签:

context('cypress/e2e/Test1.cy.ts', { tags: '@smoke' }, () =>
  require('cypress/e2e/Test1.cy.ts'))
  1. 我对
    ng e2e
    不够熟悉,无法指导您是否可以通过该命令传入 Cypress 环境变量。 (直接使用 Cypress 命令,确实会暴露这一点:
    npx cypress run --env grepTags=@smoke
    )。 但是,Cypress 环境变量可以在命令行上设置,只需在变量名称前面加上
    CYPRESS_
    cypress_
    即可。在这种情况下,您需要设置
    CYPRESS_grepTags=@smoke

0
投票

根据文档,您可以将 grep 选项添加到命令行:

# run tests tagged @fast
$ npx cypress run --env grepTags=@fast
# run only the tests tagged "smoke"
# that have "login" in their titles
$ npx cypress run --env grep=login,grepTags=smoke

所以您所需要的就是以下内容(因为

--spec
正在工作)

ng e2e --spec **/smoketest/*.cy.ts --env grepTags=@smoke
© www.soinside.com 2019 - 2024. All rights reserved.