How to group together certain tests or files when

2019-08-01 03:06发布

问题:

I am currently running Cypress and I have folders inside of it, where I have tests located for different applications. I have a folder entitled "smhw-qa" which contains sub-folders and tests files for this specific application.

This directory apps will also include other applications too in future.

What I wish to do

In order to avoid having to run every test for a run, I wish to only run this specific folder. The location of the folder is as such:

'cypress/integration/apps/smhw-qa'

Over time, there will be more folders and tests added to the apps directory.

I am familiar with how to run a specific file, so doing the following works:

npx cypress run --spec 'cypress/integration/apps/smhw-qa/banners_promos_global/global_search.js'

How can I specify to Cypress which folder to run specifically when I use the npx cypress -run command?

What I have tried already

To run a specific test file I tried:

npx cypress run --project 'cypress/integration/apps/smhw-qa'

But this provides an error instead:

Can't run because no spec files were found.

We searched for any files inside of this folder:

/Users/jaswindersingh/Documents/cypress-automation/automation/cypress/integration/apps/smhw-qa/cypress/integration

Running specific sets of tests by their folders will be much easier for me, and will save time when running a specific suite of tests on our CI platform for example. I will also not need to specify the individual files since this is time-consuming.

It would also mean I can split out my tests and run them on different machines

Do I need to put anything into my test files, or inside of cypress.json or modify anything else, or can this be achieved through the terminal? What options must I use instead?

Thanks

回答1:

Through --project you can manage different cypress.json files, the docs says

This enables you to install Cypress in a top level node_modules folder but run Cypress in a nested folder. This is also helpful when you have multiple Cypress projects in your repo.

so you're on the right way, just prepare some project-related cypress.json files



回答2:

I think the clue is in the error message, you call

cypress/integration/apps/smhw-qa

and the error message shows

cypress/integration/apps/smhw-qa/cypress/integration

so to use the --project flag you need to replicate the /cypress folder per project, as per this example cypress-test-nested-projects

Folder structure:

package.json
node_modules
src/
    clients/
        foo/
            cypress.json
            cypress/
        bar/
            cypress.json
            cypress/

However, I think you might want to use the --spec flag instead. If I understand it correctly, the glob pattern will allow you to keep the current folder structure. Docs

cypress run --spec 'cypress/integration/apps/smhw-qa/**/*'