简体   繁体   English

有什么办法可以运行cypress open并且只包含包含关键字的测试文件? 例如。 来自 domain-lifecycle.spec.jsx 的生命周期

[英]Is there any way to run cypress open and only include test files containing a key word? eg. lifecycle from domains-lifecycle.spec.jsx

I have a fairly large library of test files in my project (roughly 80) and I have them named with keywords ex.我的项目中有一个相当大的测试文件库(大约 80 个),我用关键字 ex 命名它们。 "create" "Edit" and "lifecycle". “创建”“编辑”和“生命周期”。 I want to be able to run npx cypress open and only include all the test files that contain "lifecycle" for example.我希望能够运行npx cypress open并且只包含所有包含“生命周期”的测试文件,例如。 Is there something I can add to the Cypress.json Globing wise?有什么我可以添加到 Cypress.json Globing 的明智之举吗? Thanks in advance!提前致谢!

To expand on @JosePita's idea, you can set up glob patterns in scripts (package.json) and by-pass the multitude config files he was concerned about.为了扩展@Jos​​ePita 的想法,您可以在脚本 (package.json) 中设置 glob 模式并绕过他关注的众多配置文件。

For example, these work on my system,例如,这些在我的系统上工作,

"scripts": {
  "cy:open": "cypress open",                              // all files
  "cy:user": "cypress open -c testFiles=user/**/*",       // just the user folder
  "cy:error": "cypress open -c testFiles=**/*error*.js",  // files with keyword 'error'

There's a search bar at the top of the Cypress runner, where the tests are listed, but search is all it does. Cypress runner 顶部有一个搜索栏,其中列出了测试,但搜索就是它的全部功能。

Pressing the Run all specs button runs the full set regardless of search results.无论搜索结果如何,按Run all specs按钮都会运行全套。

If you want to run a subset, specify the testFiles config option on the command line.如果要运行子集,请在命令行上指定testFiles配置选项。

From this it seems you can open it using a config file and from this you can configure what files to load on the configuration.这个看来你可以使用配置文件,打开它,并从这个可以配置哪些文件上的配置加载。

It's an ugly solution because you'd need to have multiple config files for all the keywords you need (and maintain them).这是一个丑陋的解决方案,因为您需要为您需要的所有关键字设置多个配置文件(并维护它们)。

Another option is to have your test files separated by folders, each with it's own cypress project inside ( docs and example )另一种选择是让您的测试文件由文件夹分隔,每个文件夹都有自己的 cypress 项目( 文档示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM