'How can I catch unexpected error messages during Cypress test execution?
I am using Cypress and iziToast (http://izitoast.marcelodolce.com/) to run some tests on a web application. I spotted an unexpected error message whilst running it locally. I was able to catch it by adding the following cy.toast statement to my code:
cy.get(tabbedPanelControlsTitle)
.should('have.value', 'Teams')
.click();
// this is causing the following unexpected error
cy.toast({
type: 'Error',
code: 'E1527360562',
});
I was able to get it to fail here using the following:
cy.wrap({ toast: 'Error' })
.its('toast')
.should('eq', 'Success');
What I would like to know is there any way of catching these unexpected errors?
Toast Message:
Failing that, can I get the Network response to my click() command?
Solution 1:[1]
You can try the below code. This snippet will help you to catch the exception in the cypress test flow.
Cypress.on('uncaught:exception', (err, runnable) => {
console.log("err :" + err)
console.log("runnable :" + runnable)
return false
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Prasanna Ravichandran |

