【发布时间】:2021-07-13 12:46:59
【问题描述】:
我在一个页面上有一个复杂的计算服务,点击“计算”按钮就会触发它。这将触发需要 10-30 秒的服务,因此将每 2 秒发出一次 GET 请求,除非响应在 JSON 响应中包含“calculatedRoute”数据。然后我必须根据 calculatedRoute 数据验证 UI
到目前为止,我在 Cypress 中进行了以下测试
cy.intercept("GET", "/v1/calculations/*").as("route-calculations")
cy.get('#calc').click();
cy.waitForCalculationRequest('@route-calculations', 30)
在命令中,
Cypress.Commands.add("waitForCalculationRequest", (aliasName, retries) => {
cy.wait(aliasName).its('response.body').then(json => {
cy.log(typeof json)
cy.log(json);
cy.log(json.calculatedRoute);
if (json.calculatedRoute == "") {
return
}
else if (retries > 0) {
cy.waitForCalculationRequest(aliasName, retries - 1);
}
});
});
但我无法让命令在抛出时正常工作
任何帮助将不胜感激。
在计算过程中获取响应数据(除最后一个之外的所有请求):
{
"id": 8,
"createdAt": "2021-07-13T11:39:11.756095Z",
"updatedAt": "2021-07-13T11:39:11.756095Z",
"status": "pending",
}
GET 计算完成时的响应数据(Last request):
{
"id": 8,
"createdAt": "2021-07-13T11:39:11.756095Z",
"updatedAt": "2021-07-13T11:39:41.394267Z",
"status": "complete",
"calculatedRoute": {
"route": "bla bla bla",
"subscriptions": [
x,y,z
],
}
}
【问题讨论】:
标签: cypress