Run Just The Failed Tests In Cypress

How to run the failed tests from DevTools Console using @bahmutov/cy-grep plugin.

Imagine you run all Cypress specs together using the newly resurrected "Run all specs" button. . Let's say 3 out of 30 tests fail. You modify the tests or the application source code. Can you re-run just the failed tests to see if they have been fixed? Until today you could not. In this blog post I will show the feature I have added to my plugin @bahmutov/cy-grep. It allows you to simply call 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 wrote cypress-grep plugin that added running Cypress tests by tag or part of the title. When I left the company I moved that plugin to cypress-io/cypress-grep repo. I personally think this plugin should be a core Cypress feature. The Cypress team then moved the repo into the cypress-io/cypress monorepo, a move I cannot stand. When Cypress v11 changed how the Cypress.env object worked, I needed to fix Cypress.grep() method, but I did not want to touch the Cypress monorepo. Thus I cloned the code back to my bahmutov/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!

Rerun the failed tests button mockup

See also