In cypress I'm able to pop up a assert message when get() is good and contain() or ep() fails with custom overwrite should command. But not able to figure if get() fails to locate element.
Can we overwrite the get() function.
Cypress.Commands.overwrite('should', (originalFn, assertion, expected, options) => {
if (options && options.message) {
cy.removeAllListeners('fail') // remove all 'fail' listeners
// And we're starting from fresh!
cy.on('fail', (error, runnable) => {
error.name = 'CustomError'
error.message = options.message
throw error // throw error to have test still fail
})
}
return originalFn( assertion, expected, options)
})
it('fails with custom message via overwrite of should', () => {
cy.wrap(1).should('eq', 1, { message: 'custom error message 1'})
cy.wrap(1).should('eq', 2, { message: 'custom error message 2'})
})