mercredi 21 octobre 2020

How to make Cypress wait for undetermined amount of XHR requests

In my React app, when users logs in, they get redirected to dashboard. Then, app sends a requests to "/files" endpoint, which returns paths to static files which should be then fetched one by one by separate requests like GET https://api_address/static_file/xxx The problem is, that number is never the same. Sometimes it's 10, sometimes 16 etc. Until these resources finish fetching the app displays loading screen. How can I make Cypress wait till all responses finish? I tried cy.wait() but it waits only for the first request of that type. I can't create multiple cy.wait() because as I said, I don't know the amount of the requests. I thought about trying to cy.get() the dashboard div (dashboard shows only after fetching is finished) and set the retry timeout to a really big number, but that will my tests unnecessarily slow - as I said, the number of requests is random, it can even be 1 request. Is there any way to make cypress wait till there are no active requests of specific type? Or maybe you know another way to solve this problem?

Aucun commentaire:

Enregistrer un commentaire