Reputation:
I have a cypress test for my web application, being a set of blocks:
describe('Test Page X', function () {
before(function () {
cy.navigateTo('page-x', 0)
})
it ('should work', function(){
cy.doSomething()
})
after(function(){
cy.navigateBack()
})
})
The problem is, that after() is called only when it() works, if it() failes because of some error on the page X, after() is not called, and as a result, the test got stuck on the page X, and the following tests for pages Y, Z etc. also fails.
Am I doing something wrong here? How to make after() that is always called?
Upvotes: 1
Views: 3134
Reputation: 8322
There might be a technical solution, but there's an architectural solution.
Cypress discourages using after hooks for cleaning states after your tests. That's basically what you do right now.
if it() failes because of some error on the page X, after() is not called, and as a result, the test got stuck on the page X, and the following tests for pages Y, Z etc. also fails.
That has an easy solution in that you can navigate to pages Y, Z from before hooks, or directly from the tests.
You can check Cypress recommendation on this topic here.
Upvotes: 3