Imagine you run all Cypress specs together using the newly resurrected "Run all specs" button. Cypress.grepFailed()
from the browser's DevTools Console and voilรก - the failed tests execute, while the rest of the tests are skipped.
In the video below I show a single failed test among many successful tests. Then I run just that test by executing Cypress.grepFailed()
from the DevTools Console. This repeats the single test and it fails again. Then I fix the test and it automatically reruns, showing that is is passing. Then I reset the failed tests filter by running the Cypress.grep()
from the console, and Cypress starts running all tests again.
๐ You can find the complete project setup used as an example in the repo bahmutov/test-todomvc-using-app-actions.
- Follow the @bahmutov/cy-grep README instructions on how to use this plugin in your project
- You can run the failed tests in a single spec or when using the "Run all tests"
- We use this grep plugin across MercariUS to run lots of end-to-end tests by feature, see my presentation .
๐ค What is
@bahmutov/cy-grep
plugin? A long time ago I wrotecypress-grep
plugin that added running Cypress tests by tag or part of the title. When I left the company I moved that plugin tocypress-io/cypress-grep
repo. I personally think this plugin should be a core Cypress feature. The Cypress team then moved the repo into thecypress-io/cypress
monorepo, a move I cannot stand. When Cypress v11 changed how theCypress.env
object worked, I needed to fixCypress.grep()
method, but I did not want to touch the Cypress monorepo. Thus I cloned the code back to mybahmutov/cy-grep
repo and released my first feature: running the failed tests ๐
What Cypress needs
Cypress superpower is its GUI - the left side of the browser window that shows the Command Log. Cypress needs to expose an API for plugins to register UI components that call the API or control its functionality. For example, the above example would be so much better if my plugin could add another button next to "Rerun tests" button!
See also
- ๐ blog post How To Tag And Run End-to-End Tests
- ๐ blog post Burning Tests with cypress-grep
- ๐ blog post Faster test execution with cypress-grep
- ๐ blog post Repeating Tests