Wait for multiple XHR requests to the same url or endpoint

你说的曾经没有我的故事 提交于 2019-12-13 17:41:56

问题


In Cypress, I have multiple requests that will match my cy.route() declaration. I want to make sure more than one request is made on the route. How do I tell Cypress to wait for multiple XHR requests to the same url?


回答1:


From the Cypress Docs:

You should set up an alias (using .as()) to a single cy.route() that matches all of the XHRs. You can then cy.wait() on it multiple times. Cypress keeps track of how many matching XHR requests there are.

cy.server()
cy.route('users').as('getUsers')
cy.wait('@getUsers')  // Wait for first GET to /users/
cy.get('#list>li').should('have.length', 10)
cy.get('#load-more-btn').click()
cy.wait('@getUsers')  // Wait for second GET to /users/
cy.get('#list>li').should('have.length', 20)


来源:https://stackoverflow.com/questions/50472827/wait-for-multiple-xhr-requests-to-the-same-url-or-endpoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!