In cypress, how do I wait for a page to load?

前端 未结 1 388
無奈伤痛
無奈伤痛 2020-12-31 08:15

Don\'t tell anyone, but our app is not yet single-page. I can wait on a given XHR request by giving the route an alias, but how do I wait until some navigation compl

相关标签:
1条回答
  • 2020-12-31 09:14

    You can add some assert inside:

    cy.click('#someButtonToNavigateOnNewPage');
    
    cy.location('pathname', {timeout: 60000})
      .should('include', '/newPage');
    
    cy.click('#YouAreOnNewPage');
    

    You can change default timeout - by default it's 4000 ms (4 secs) - to ensure that user navigated the page. I've put a big number here - 60,000 ms - because I'm sure that 99% of users will leave if they do not have page loaded after 1 min.

    0 讨论(0)
提交回复
热议问题