2

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

Pratik Patel
  • 2,209
  • 3
  • 23
  • 30
  • 1
    There is a 3rd party lib recommended for this scenario [cypress-wait-until](https://github.com/NoriSte/cypress-wait-until). Not used it, but the concept looks good. – Richard Matsen Feb 28 '20 at 08:58
  • Oh hey the author has added some info [here](https://stackoverflow.com/a/60446878/4716245) – Richard Matsen Feb 28 '20 at 09:11

0 Answers0