How to wait for two parallel XHR requests in Cypress

本小妞迷上赌 提交于 2019-12-07 07:20:47

问题


I know that it is possible to wait for multiple XHR requests on the same url as shown here. However, I would like to wait for two requests running in parallel.

cy.wait('@users')
cy.wait('@users')

When I add two waits as shown above, the second one sometimes timeouts when they finish very closely together, as it basically misses the XHR.

CypressError: Timed out retrying: cy.wait() timed out waiting 30000ms for the 1st response to the route: 'users'. No response ever occurred.

I do not like the introduction of flakiness. Is there a better way to write this that I am missing?


回答1:


You can wait for an array of aliases, I haven't tried it with multiple calls to the same route, but I think it should do the trick.

cy.wait(['@users', '@users'])



回答2:


I've created an example which will blindly wait for all your pending requests to finish before proceeding, you can check the implementation here. https://github.com/PinkyJie/cypress-auto-stub-example#more-detail-for-implementation



来源:https://stackoverflow.com/questions/51857888/how-to-wait-for-two-parallel-xhr-requests-in-cypress

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