I recently faced a scenario where UI component(with XHR request /get_data
) is getting loaded on a page after a certain amount of time(let say 10 seconds), and it's not automatic. So I need to reload the page(polling) after 1 second and again need to wait for the XHR request, this process is continuous till I get the request.
If it was automatic call then
cy.route('/get_data').as('getData').wait('@getData',{requestTimeout: 15000})
would have worked
To avoid this I made a custom function(which is not working):
while (true) {
try {
cy.reload()
cy.wait('@getLogs') //But here this ERROR can't be catched!
return false
} catch (e) {
cy.wait(1000)
}
}
I am getting below error:
CypressError: Timed out retrying: cy.wait() timed out waiting 2000ms for the 1st request to the route: 'logRequest'. No request ever occurred.
The above function could be worked if wait()
could be caught! I know this code is not ideal but I am not sure about the more appropriate way.
Thank you