I'm testing a heavy page with cypress, and I need to wait until there are no active XHR requests, I have tried to use Cypress.$.active === 0, but this is always true even when there are active ones. What should I do?
Asked
Active
Viewed 1,041 times
1
-
I believe Cypress only has built-in support to wait for stubbed XHR requests. There's no built-in support wait for non-stubbed requests to finish. Would it be possible to simply wait for a certain button to appear? In addition, what are you trying to test? – natn2323 May 08 '20 at 15:52
-
I have no way to know how many requests I'm waiting for, that's why I need to find a function outside cypress to do it. And I'm trying to not rely on animations only, because my tests are not written for a specific element – Eduardo Carneiro May 09 '20 at 16:59
1 Answers
1
In Cypress you can wait on intercepted requests. You do not have to stub the response for these requests, by default they will still call their original destination.
cy.intercept('/**').as('ajax-requests');
...actions that trigger AJAX requests...
cy.wait('@ajax-requests');

notclive
- 2,897
- 1
- 17
- 14