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

121
Views
How to handle cypress erros?

Let's say I have simple test:

/// <reference types="cypress" />

describe('Something important', () => {

  it('First test', () => {
    ...
  })

})

And what I need to do is to handle if something happens in First test, I was trying something like, but it doesn't work this way:


it('First test', () => {
    try {
      ...
    } catch (e) {
      ... // send email, for example
    }  
})

So, in some way I need to handle whatever happens in test. Is it possible? Something like this, but for whole test:

cy.get('button').contains('hello')
  .catch((err) => {
    // oh no the button wasn't found
    // (or something else failed)
    cy.get('somethingElse').click()
  })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Is this what you need Catching Test Failures?

Cypress.on('fail', (error, runnable) => {
  debugger

  // we now have access to the err instance
  // and the mocha runnable this failed on

  throw error // throw error to have test still fail
})

This will fire when the test fails, so you can perform your email or other action.

But generally Cypress expects you to know that the button will be there. You shouldn't have too many unpredictable things on the page (or not on the page, as the case may be).

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!