I have a test case to fix a bug that appears 1 in X times.
I'd like to run the same test multiple times but I can't find any documentation that explains how to restart the test automatically and stop when a threshold is hit.
Any insight is appreciated
You can add the testing block inside a loop.
Cypress is bundled with a few libraries, lodash can do this using: Cypress._.times method:
Cypress._.times(10, () => {
describe('Description', () => {
it('runs 10 times', () => {
//...
});
});
});
Instead of putting the loop inside the test, you could put it in the outer space as following
var i = 0;
for (i = 0; i < 3 ; i++) {
describe('Verify "Login" is visible. Test: '+i, function() {
it('finds the Login link in the header', function() {
//Place code inside the loop that you want to repeat
})
})
}
The Result will be the following:
I completely spaced and forgot that these are normal JS files, so I wrapped the test in a for loop. This seems to work as I expected.
describe('Verify "Login" is visible', function() {
it('finds the Login link in the header', function() {
var i = 0;
for (i = 0; i < 5 ; i++) {
//Place code inside the loop that you want to repeat
cy.visit('https://www.example.com/page1')
cy.get('.navbar').contains('Login').should('be.visible')
cy.visit('https://www.example.com/page2')
cy.get('.navbar').contains('Login').should('be.visible')
}
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With