如何在赛普拉斯中等待两个并行的XHR请求 [英] How to wait for two parallel XHR requests in Cypress

查看:101
本文介绍了如何在赛普拉斯中等待两个并行的XHR请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以在同一网址上等待多个XHR请求,如下所示:此处。但是,我想等待两个并行运行的请求。

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')

当我添加两个以上所示的等待时,第二个当它们紧密靠近在一起时,有时会超时,因为它基本上错过了XHR。

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?

推荐答案

您可以等待一个别名数组,我还没有尝试过多次调用同一条路由,但是我认为它应该可以解决问题。

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'])

这篇关于如何在赛普拉斯中等待两个并行的XHR请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆