How can I catch unexpected error messages during Cypress test execution?

别来无恙 提交于 2019-12-11 15:46:13

问题


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?


回答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
})


来源:https://stackoverflow.com/questions/54829276/how-can-i-catch-unexpected-error-messages-during-cypress-test-execution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!