I have a bunch of Cypress tests in node.js. I can fire them off using npm run
eg npm run home-page-test
and can string them together as such:
npm run home-page-test && npm run about-page-test && npm run contact-page-test
.
The problem I am having is that if an it
block fails in one test the test (spec file it is on) will complete, but NPM or Node will not continue on to the next test/spec file.
For example, on home-page-test
if an assertion within it
block 4 of 7 fails, all 7 it
blocks will still run and the entire home page test will be completed, but the next test in the string (npm run about-page-test
) will not run at all (until the problem is fixed).
Does anyone know if there is a way to achieve this?
(Examples below)
npm run home-page-test && npm run about-page-test
//home-page-test.spec.js
describe('I am on the Home page', () => {
it(`Does this`, () => {
// test (passes)
})
it(`Does something else`, () => {
// test (passes)
})
it(`Does SOMETHING THAT FAILS`, () => {
// test (fails)
})
it(`Does someting else`, () => {
// test (passes)
})
//etc...
});
//about-page-test.spec.js
// WONT run because 'it' block 3 above fails
describe('I am on the About page', () => {
it(`Does this`, () => {
// test (passes)
})
//etc...
});
One thing you can do is combine the specs into a single "batch".
If you make a spec file called, for instance, home-about.spec.js
that imports the home spec and about spec
import './home-page-test.spec.js'
import './about-page-test.spec.js'
The command yarn cypress run --spec cypress/e2e/home-about.spec.js
produces the following results
That method might be a bit simplistic, depending on what your npm run home-page-test
, npm run about-page-test
, etc commands are doing.
It might be better to create a NodeJs script and running the Cypress API Module, where you can add various options and also process results and errors.
// e2e-run-tests.js
const cypress = require('cypress')
cypress
.run({
spec: [
'./cypress/e2e/home-page-test.spec.js',
'./cypress/e2e/about-page-test.spec.js',
]
})
Run it with the command node e2e-run-tests.js