jeudi 8 avril 2021

Cypress: Conditional AssertionError

Is there a way to NOT abort a test run if an AssertionError appears?

My test case is dependent on CSS values and if I write a condition like the one below, cypress stops with an AssertionError:

let dialog = cy.get('#privacy_dialog')
if (dialog.should('have.css', 'display', 'block')) {
  // confirm the dialog if it is displayed
  cy.get('#dialog_btn').click()  
} else {
  // process with login, because css in this case is "display: none;"
  cy.get('#login_btn').click()
}

It also wouldn't work this way, because then I get another error TypeError $dialog.should is not a function:

cy.get('#privacy_dialog').then(($dialog) => {
  if ($dialog.should('have.css', 'display', 'block')) {
    cy.get('#dialog_btn').click()
  } else {
    cy.get('#login_btn').click()
  }
})

Aucun commentaire:

Enregistrer un commentaire