Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reliable way to have Cypress exit as soon as a test fails?

We have a large test suite running on a CI server, and there appears to be no way of telling Cypress to exit if a test fails. It always runs the entire suite.

There is some discussion here, but no workable solution.

Is there a reliable way to have Cypress exit as soon as a test fails?

like image 230
Undistraction Avatar asked Nov 01 '19 10:11

Undistraction


People also ask

How do you abort a cypress test?

Cypress gives us the ability to stop the test at a spot via cy. pause() command. We can use this to stop the test before any action or assertion that is causing our tests to fail.

How do you run failed test cases in Cypress?

You can configure this in the Cypress configuration by passing the retries option an object with the following options: runMode allows you to define the number of test retries when running cypress run. openMode allows you to define the number of test retries when running cypress open.

What is retry ability in Cypress?

The retry-ability allows the tests to complete each command as soon as the assertion passes, without hard-coding waits. If your application takes a few milliseconds or even seconds to render each DOM element - no big deal, the test does not have to change at all.


1 Answers

You can also use this Cypress plugin meanwhile Cypress does not support this feature natively: https://www.npmjs.com/package/cypress-fail-fast

Add the plugin to devDependencies:

npm i --save-dev cypress-fail-fast

Inside cypress/plugins/index.js:

module.exports = (on, config) => {
  require("cypress-fail-fast/plugin")(on, config);
  return config;
};

At the top of cypress/support/index.js:

import "cypress-fail-fast";
like image 72
Javier Brea Avatar answered Sep 25 '22 02:09

Javier Brea