How can I overcome a situation when the element is not found. I am automating a form where intentionally I am giving a duplicate name so an error message will be shown "Limit Name already exist" based on that I have written
add.limitName().type('Movie Limits') // Giving duplicate name "Movie Limits"
cy.get('.has-error > .col-sm-6 > [data-bv-validator="remote"]').then((wizard) => {
if(wizard.text().includes('Limit Name already exist.')) // Duplicate Limit Name Check
{
add.limitName().clear()
add.limitName().type('Movie TR Limits') // Giving another Name
}
})
This works perfectly fine if its a duplicate value but if its not a duplicate value then this element wont be found and an error is thrown and the test fails. How can i write in such a way if its not duplicate it carries on and if it is the above code comes into action ?
You can check the error class after the
.type()
command