Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cypress after() called only after success

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading