Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!