我正在try 验证来自OpenweatherAPI的API响应.
我正在执行以下步骤
- 创建带有POST呼叫的气象站
- 从步骤1获取外部ID
- 将外部ID与GET RESPONSE匹配并通过测试.如果在GET响应中未找到外部ID,则测试失败
it.only('first POST and array iteration', () => {
cy.request({
method: 'POST',
url: 'https://api.openweathermap.org/data/3.0/stations?appid=7fe67bf08c80ded756e598d6f8fedaea',
headers: {
'Accept': 'application/json'
},
body: {
"external_id": "testweatherapi12",
"name": "weather_api12",
"latitude": 35.55,
"longitude": 89.45,
"altitude": 56.4
}
}).then((res) => {
cy.log('response is ' + JSON.stringify(res));
let idIs = res.body.ID;
cy.log('ID****** is ' + idIs);
expect(res.status).to.eq(201)
}).then((res) => {
cy.request({
method: 'GET',
url: 'https://api.openweathermap.org/data/3.0/stations?appid=7fe67bf08c80ded756e598d6f8fedaea',
headers: {
'Accept': 'application/json'
}
}).then((res) => {
for (var x = 0; x < res.body.length; x++) {
expect(res.body[x].id).to.eq(res.body.ID); //This is failing
}
})
})
})