【发布时间】:2019-09-09 15:27:44
【问题描述】:
当我调用 URL 时,会发送未定义数量的请求。
现在我尝试找出其中一个请求是否包含某个有效负载。
cy.server();
cy.visit(url);
cy.route({
method: 'POST',
url: '**/t/e/**',
}).as('xhrRequest');
到目前为止,我在How to capture all API calls in cypress? 上找到了类似的方法。 这里的问题是假设有固定数量的 API 调用。
cy.wait(Array(60).fill('@xhrRequest'), { timeout: 30000 }).then((xhrs) => {
xhrs.forEach((res) => {
expect(res.status).not.to.be.null
})
})
如果没有包含有效负载的单个请求,我如何知道所有请求都被拦截并且我的测试失败。
我已经在 puppeteer 中写过类似的东西
let hasSpecialRequest = false;
page.on('request', request => {
if (isSpecialRequest(request)) {
hasSpecialRequest = true;
}
request.continue();
});
await page.setRequestInterception(true);
expect(hasSpecialRequest).to.equal(true);
系统检查每个请求是否是特殊请求之一,并相应地设置变量。我尝试用 Cypress 重新创建这样的东西。
【问题讨论】:
标签: javascript cypress