等待多个XHR请求到相同的URL或端点 [英] Wait for multiple XHR requests to the same url or endpoint

查看:75
本文介绍了等待多个XHR请求到相同的URL或端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在赛普拉斯,我有多个与我的 cy.route()声明匹配的请求。我想确保在路线上做出多个请求。

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?

推荐答案

如何从赛普拉斯文档

您应该设置别名(使用。as())到单个 cy.route()匹配所有XHR。然后,您可以对其多次 cy.wait()。赛普拉斯会跟踪有多少匹配的XHR请求。

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)

这篇关于等待多个XHR请求到相同的URL或端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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