Example application with grep tags inside the test names
The demo example for the @bahmutov/cy-grep plugin.
Watch the video intro to cypress-grep which shows how this repository tags tests, uses @bahmutov/cy-grep plugin, and sets up the TypeScript intelligent code completion.
You can also watch How I organize pull request workflows where I show how the GitHub workflows in .github/workflows are organized to run the smoke tests first on pull request.
Read the blog post Trigger Selected Cypress Specs Using GitHub Actions
Before filtering by test title and tag, we need to install dependencies and start the application
$ npm install
$ npm start
We can pick some tests to run using part of their title.
$ npx cypress run --env grep="the current number of todo items"
Runs just a single test found in cypress/integration/counter-spec.js. The rest of the tests are still loaded, but are marked pending. To really target specific tests, add --spec ...
argument
$ npx cypress run --env grep="the current number of todo items" \
--spec cypress/integration/counter-spec.js
Some tests in this repo in the cypress/integration folder have the tag @smoke
in their config object. The symbol @
has no meaning, I just like to use this prefix to make tags searchable.
// cypress/integration/routing-spec.js
describe('TodoMVC - React', function () {
context('Routing', function () {
// other tests
it('should allow me to display all items', { tags: '@smoke' }, function () {
...
})
// if you have more than one tag, use an array
it('should respect the back button', { tags: ['@smoke'] }, function () {
...
})
})
})
To run just the tests with substring @smoke
you can do:
$ npx cypress run --env grepTag=@smoke
cypress-grep: filtering using tag "@smoke"
See the .github/workflows/main.yml that first runs the smoke tests and then all the tests during the CI run. You can see the runs in the repo's Actions tab.
You can run the selected tests multiple times by using the burn=N
parameter. For example, run all all the tests in the spec A five times using:
$ npx cypress run --env burn=5 --spec cypress/integration/A.js
# run the smoke tests 3 times
$ npx cypress run --env grepTag=@smoke,burn=3
See the pull request #79 that updates this repo to use Cypress v10
To see the test names and their tags, run npm run print-tests
which uses find-cypress-specs.
You can use the included dennisbergevin/cypress-cli-select to manually select the tests / tags / specs to run
$ npx cypress-cli-select run
Cypress-cli-select
? Choose to filter by specs, specific test titles or tags:
(Press <tab> to select/deselect, <ctrl> + <a> to toggle all, <enter> to proceed)
>[ ] Specs
[ ] Test titles or tags (requires cy-grep)
📺 watch the video Intro To The cypress-cli-select Plugin.
This project includes cypress-plugin-grep-boxes plugin to allow filtering the tests to run in the cypress open
mode
📺 watch the video cypress-plugin-grep-boxes Plugin Demo
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2021
License: MIT - do anything with the code, but don't blame me if it does not work.