【发布时间】:2021-09-08 17:29:54
【问题描述】:
在我的应用程序中,我有一个流程,它触发了对相同端点的两个 POST 请求,但请求正文略有变化。我们如何使用 cypress 实现这一目标?
请求 1:
请求网址:http://localhost:8000/weather/F20210908060000/spot
请求方法:POST
请求正文:
{
"locations": [
{
"timestamp": "2021-09-18T06:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T07:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
}
],
"elements": [
2
]
}
请求 2: 请求网址:
http://localhost:8000/weather/F20210908060000/spot
请求方法:POST
请求正文:
{
"locations": [
{
"timestamp": "2021-09-18T04:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T05:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T06:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T07:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
}
],
"elements": [
2
]
}
注意:请求 2 的请求中有更多数据。
到目前为止我的代码:
cy.intercept("POST", "**/spot", (req) => {
expect(req.locations).to.have.length.above(3);
}).as('postSPOT1');
Weather.activateSPOTWeather()
});
cy.wait('@postSPOT1').its('response.statusCode').should("eq", 200);
【问题讨论】:
标签: cypress