I have an API that returns times in a day and if those times are all taken then it won't return any. I want to move to the next day and try and check for times there but my test gets stuck and will crash.
So if there are no times go to the next day and wait for the response and check again for times. If there are times return we can exit the loop. Anyone see where this is going wrong?
Thanks
cy.get('body').then(($body) => {
while (true) {
if ($body.find('.time').length) {
break
} else {
cy.get('.day').eq(4).click()
cy.wait('@apiCheck2')
cy.wait(500)
}
}
})
wrap
andeach
– Higgle.each()
since the DOM changes each iteration. – Lizalizabethcy.wrap(selector).each((index) => {
allows you to iterate the cypress promises but I have no way of testing this so I could totally be wrong – Higglecy.wrap(selector)
is not valid syntax, you needcy.get(selector)
. In the linked answer they wrap an array not a selector, and the.each()
sees a fixed range of values - nothing changes in the iteration. – Lizalizabeth$body
isn't varying in the loop, even though the DOM has changed. – Lizalizabeth