【问题标题】:Unable to run tests in a specific location无法在特定位置运行测试
【发布时间】:2020-11-30 05:41:11
【问题描述】:

我在默认的/cypress/integration 目录中模拟了集成测试,并在/cypress/e2e 中进行了端到端测试。我正在尝试将脚本添加到我的 package.json 文件中,该文件将专门运行 E2E 测试。

我定义了以下脚本:

  "scripts": {
    "cy:run": "cypress run",
    "test:e2e": "npx cypress run --spec \"cypress/e2e/**/*.spec.ts\"",
  }

当我执行npm run test:e2e 时,我看到以下内容:

npx cypress run --spec "cypress/e2e/**/*.spec.ts"

无法运行,因为找不到规范文件。

我们搜索了与此 glob 模式匹配的所有文件:

柏树\e2e***.spec.ts 我还尝试使用以下两个命令在命令行中运行特定测试,但结果相同:

npx cypress run --spec "cypress\e2e\enterprise\taxpayer.spec.ts"

npm run cy:run -- --spec "cypress\e2e\enterprise\taxpayer.spec.ts"

spec 文件本身以describe() 功能块开头。

This 回答说你可以使用等号,但这也不适合我。

知道赛普拉斯为什么无法识别我的测试吗?

【问题讨论】:

    标签: cypress


    【解决方案1】:

    应该通过cypress.json 更新您的规范文件夹(它位于您的cypress 文件夹之外和根目录内)。您需要包含以下内容:

    "integrationFolder": "./cypress/e2e"
    

    因此,CLI 应该是:

    npx cypress run --spec "cypress/e2e/enterprise/taxpayer.spec.ts"
    

    其他配置(例如截图文件夹等)可以在这里找到: https://docs.cypress.io/guides/references/configuration.html#Folders-Files

    【讨论】:

    • 这是默认文件夹位置设置。我对此很熟悉。不过,您应该能够随时运行任何规范文件,不管它是否在定义的规范文件夹中,不是吗?
    • 啊哈。抱歉有点误会了。尝试在cypress.json 中使用此"integrationFolder": "./"。如果可行,我会更新我的答案。
    猜你喜欢
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多