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

huangapple go评论59阅读模式
英文:

Can't Run Beacause No Spec file found Cypress

问题

我正在使用 Cypress 版本 9.0.0,并在我的集成文件夹中创建了 Product1 和 Product2。我正在使用无头模式运行测试用例,使用以下命令 -

./node_modules/.bin/cypress run --spec cypress/integration/Product2/testcases/Login.spec.js

我的目录结构如下:

cypress/
   fixture/
   integration/
   Product1/
     testcases/
       Login.spec.js
       testlist   ---> testlist 包含文件名,例如:Login.spec.js
     usecases/
     testlist     ---> testlist 包含文件夹名,例如:testcases usecases
     constant.js
   Product2/
     testcases/
       Login.spec.js
       testlist     ---> testlist 包含文件名,例如:Login.spec.js
     usecases/
     testlist       ---> testlist 包含文件夹名,例如:testcases usecases
     constant.js

出现错误信息 -

找不到规范文件,无法运行
我们搜索匹配此通用模式的规范文件:

/root/temp/abc/UI/cypress/integration/Product2/testcases/Login.spec.js

但如果我使用 Product1,

命令

/root/temp/abc/UI/cypress/integration/Product1/testcases/Login.spec.js

它可以正常工作,测试用例可以成功运行。

我尝试了以下可能性,

  1. 在 cypress.json 中更改 "specPattern":"cypress/integration/**/*.js"
  2. 在集成中添加了包含 Product1 和 Product2 的 testlist
  3. 尝试 GitHub 讨论
  4. 使用
    npx cypress run --config integrationFolder=cypress/integation/Product2/testcases/Login.spec.js
    之后,所有 Product1 的测试用例都可以运行。
英文:

I am using Cypress version 9.0.0 and I have created Product1 and Product2 in my integration folder.I am using headless mode to run testcases using command -

./node_modules/.bin/cypress run --spec cypress/integration/Product2/testcases/Login.spec.js

my Directory structure is like:

cypress/
   fixture/
   integration/
   Product1/
     testcases/
       Login.spec.js
       testlist   --->testlist contain fileName ex:Login.spec.js
     usecases/
     testlist     ---->testlist contain folderName ex:testcases usecases
     constant.js
   Product2/
     testcases/
       Login.spec.js
       testlist     ---->testlist contain fileName ex:Login.spec.js
     usecases/
     testlist       ---->testlist contain folderName ex:testcases usecases
     constant.js

getting error as-
Can't run because no spec files were found
We searched for specs matching this glob pattern:
>/root/temp/abc/UI/cypress/integration/Product2/testcases/Login.spec.js

but if i used for Product1 ,
command
>/root/temp/abc/UI/cypress/integration/Product1/testcases/Login.spec.js

it Works fine and testcase run successfully.

I have Tried possibilities,

  1. Changed in "specPattern":"cypress/integration/**/*.js" in cypress.json
  2. Added testlist in integration which contain Product1 Product2
  3. Tried github Discussion
  4. used

    npx cypress run --config integrationFolder=cypress/integation/Product2/testcases/Login.spec.js

    after this,all testcases run for Product1

答案1

得分: 2

The Product1 and Product2 folders are shown at the same level as cypress/integration, so you can't get to them with specPattern: 'cypress/integration/**/*.js' - that will preclude those folder.

If you made a mistake in the folder diagram, then your simplest option is to change specPattern to an array

{
  ...
  specPattern: [
    'cypress/integration/**/*.js',   // entry for specs under integration
    '**/Product1/**/*.js',           // specs under Product1
    '**/Product2/**/*.js',           // specs under Product2
  ]
}
英文:

The Product1 and Product2 folders are shown at the same level as cypress/integration, so you can't get to them with specPattern: 'cypress/integration/**/*.js' - that will preclude those folder.

If you made a mistake in the folder diagram, then your simplest option is to change specPattern to an array

{
  ...
  specPattern: [
    'cypress/integration/**/*.js',   // entry for specs under integration
    '**/Product1/**/*.js',           // specs under Product1
    '**/Product2/**/*.js',           // specs under Product2
  ]
}

huangapple
  • 本文由 发表于 2023年4月4日 15:01:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定