-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
on('fail') not reliably continuing test after failure #28218
Comments
"Title" should be a short text describing the issue, not your professional title. |
Yah I'm seeing some different, but similar behavior when I run this. This code does not run the cy.wrap commands. I feel like this may be expected, but maybe poorly documented in our docs. /// <reference types="Cypress" />
describe('suite', () => {
it('test', () => {
cy.on('fail', (err,runnable) => {
console.log("*****Error")
console.log(err)
return false
})
cy.visit('https://google.com')
cy.get('[data-cy]') // Assertion fails (but should continue testing)
cy.wrap(false).should('be.false') // Does not run at all
cy.wrap(false).should('be.true')
});
}); |
According to the comments in this would be expected: cy.visit('index.html')
cy.get('button#does-not-exist', { timeout: 1000 }).click()
// note: after the cy.get fails and the test fails
// the remaining commands are NOT executed
// thus this failing assertion never gets to run
cy.wrap(false).should('be.true') (Issue is also posted to https://discord.com/channels/755913899261296641/1168655650994270339/1168655650994270339.) |
Opened a PR to docs to clarify this: cypress-io/cypress-documentation#5554 |
There is a pretty good article https://www.lambdatest.com/learning-hub/exception-handling-in-cypress#fail describing the expected result when catching an error with cy.on('fail'). However in the screenshots of my sample, the test fails (in red), and even more in the screenshot you can see in the console that it never enters in the handler function associated to the cy.on('fail'). So independently if the rest of assertions are not run, the event is not properly handled (even more, if the code is aborted, what's the point of capturing the 'fail' event?). Is it missing some configuration option somewhere, to get the 'fail' event captured? |
Current behavior
The cy.on('fail') code below should catch the 2 failed assertions (and print in the console, and and finalize the test as passed.
However the test fails/stops in the first failed assertion, and even do not enter in the cy.on('fail') function:
BTW: I also tried Cypress.on('fail') within the describe outside de test and in the e2e.js with no success.
Desired behavior
No response
Test code to reproduce
Cypress Version
13.4.0
Node version
18.14.2.
Operating System
Windows 10
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: