First at all im newbie in automation test!
Well, I'm trying click every element from a list and for every element clicked the url change. So I want to stop the loop when the url match with my regex.
[List of elements][1] In the picture I marked the element that change the url /&selectedPaymentMethodId=70/
To do the first step i have the following code that obtains the list of elements to be clicked:
cy.get('.CheckoutPayment-wrapper > div:nth-child(1) > div > div > div >')
.each(($el,index,collection) => {
for (let i = 0; i <$el.length; i++ ) {
cy.wrap($el).eq(i).then($size => {
if ($size.length) {
cy.wrap($el).click()
Cypress.on('uncaught:exception', (err, runnable) => {
cy.url().should('not.match', /&selectedPaymentMethodId=70/)
return false
})
}
})
}
}
I put an exception to no fail the test and continue but I don't know how to stop the loop when the executions will found the match
PD: I used some parts of code from another mates in the community! [1]: https://i.stack.imgur.com/TXEir.png