so I'm trying to use something like "error catching" to catch an error, cy.log a custom error message, then continue with the test without error catching after that point.
For example, clicking a button that increases quantity in cart, then asserting a change in the quantity #.
//some sort of error catching here which suppresses the error, and cy.logs
cy.get("#AddToCart").click()
cy.get("#cart-count", timeout: 2000).should(contain, 2)
//disable error catching here
cy.get("#cart-count", timeout: 6000).should(contain, 2)
I tried something like
cy.on("error", (err, runnable) => {
expect(err.message).to.include("blue");
cy.log("this single test failed, but continue other tests");
return false;
});
cy.get(".cy-prc")
.should("be.visible")
.invoke("text")
.should("include", "blue");
Where the .should("include", "blue") should fail. If I can get this to fail and cy.log, then find a way to disable the error catch and do the 2nd assertion, I think I could get this working as I'm hoping it to.
Edit: We're trying to measure potential performance issues within a certain threshold, and have a custom warning printed to console when a threshold is exceeded without failing the test. We have several components or elements that can be affected by small changes in the backend, and we'd like to have warnings when we're approaching an unacceptable threshold before they become failing criteria.
There's a couple of command: events that might be useful
const commands = []
function commandStart(cmd) {
const id = cmd.attributes.id
commands.push({
...cmd.attributes,
started: +new Date(),
})
}
function commandEnd(cmd) {
const entry = commands.filter(c => c.id === cmd.attributes.id)[0]
entry.ended = +new Date()
entry.duration = entry.ended - entry.started
}
Cypress.on('command:start', commandStart)
Cypress.on('command:end', commandEnd)
cy.get("#AddToCart").click()
cy.get("#cart-count", timeout: 2000).should(contain, 2)
The commands will look like
so to check the 2nd command
cy.then(() => {
cy.wrap(commands[1])
.its('duration')
.should('be.lt', 6000)
// turn off command duration
Cypress.off('command:start', commandStart)
Cypress.off('command:end', commandEnd)
})