How do you reliably wait for page idle in cypress.

2019-05-01 01:33发布

When using cypress.io to test an angular web page, whats the best / most reliable way to detect when the page is fully loaded and idle. Not just the onload event. Needs to include all XHR requests, angular digest cycles complete and all rendering complete including all animations complete.

The reason is that at this point I want to test that the page does NOT contain an element and cant test that until all the above is fully complete.

1条回答
smile是对你的礼貌
2楼-- · 2019-05-01 01:59

You can make Cypress wait for any request to complete before it proceeds. So if you want to wait for all XHR of a certain page, you can do the following for each of them. How long it waits is defined by the responseTimeout configuration.

cy.server();
cy.route('**/api/getData').as('getData');
cy.visit('/home');
cy.wait('@getData');

Cypress best practices: Unnecessary-Waiting.

Cypress docs on wait Alias.

查看更多
登录 后发表回答