cy.get('body').then(($body) => { if ($body.text().includes('Withdrawn')) { cy.contains('Withdrawn') .click({force:true}) } else if ($body.text().includes('More')) { cy.contains('More') .click({force:true}) cy.wait(10000) cy.contains('Withdrawn') .click({force:true}) })Hola, soy nuevo en cypress y deseo repetir la declaración if nuevamente hasta que se encuentre el elemento 'Retirado' en el cuerpo haciendo clic en el botón más. ¿Alguien puede decirme cuál es la mejor manera de ejecutar esto?
No estoy seguro de si este es precisamente el código correcto, pero la idea es llamar recursivamente al código que tiene para una sola iteración.
const clickUntilWithdrawn = ($parent, attempts = 0) => { if (attempts > 10) throw 'Failed to find' if ($parent.text().includes('Withdrawn')) { cy.contains('Withdrawn').click() return } cy.contains('More').should('be.visible').click() cy.wait(10000) // probably can be shorter wait with visibility check above clickUntilWithdrawn($parent, ++attempts) } cy.get('parent-element-of-withdrawn') .then($el => clickUntilWithdrawn($el))