简体   繁体   中英

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. "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. Is there something I can add to the Cypress.json Globing wise? 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.

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.

Pressing the Run all specs button runs the full set regardless of search results.

If you want to run a subset, specify the testFiles config option on the command line.

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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