简体   繁体   中英

Cypress.io - Waiting Too Long for Pages to Finish Loading

I often experience the following sort of situation:

cy.visit(loginUrl);

cy.get('txtUsername');
cy.type('John Smith');
cy.get('btnLogin').click();

The page appears right away and displays the expected fields and controls, but Cypress continues to wait for several seconds for other ephemeral page-load tasks (scripts to finish loading, possibly? Trivial callouts to Google Analytics?) to complete before it begins interacting with the fields.

I would prefer for Cypress to begin interacting with the fields as soon as they are available. The total runtime of my test suite would improve dramatically if Cypress didn't wait longer than it needed to.

It isn't the best solution, I know, but you could remove the slowing down scripts passing a onBeforeLoad option to your visit call. The docs say

onBeforeLoad is called as soon as possible, before your page has loaded all of its resources. Your scripts will not be ready at this point, but it's a great hook to potentially manipulate the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM