摘自:https://blog.csdn.net/zengting927/article/details/79826649
问题:
每次测试计划执行完成后,执行结果列表中都会新增一条执行数据
想要通过查询结果列表接口,判断每次的最新结果中,是不是所有用例都执行成功
一、请求示例
1、请求想要的请求,并查看其接口返回值
接口对应页面:
(想要判断每次执行完以后,通过数是否为 20)
实际接口返回如下:
{ "code": "999999", "msg": "成功", "data": { "data": [ { "id": 9911, "plan": "882", "startTime": "2022-10-13 15:19:13", "endTime": "2022-10-13 15:19:20", "pass_num": 20, "fail_num": 0, "error_num": 0, "notrun_num": 0, "errorCode": 1 }, { "id": 9910, "plan": "882", "startTime": "2022-10-13 15:13:02", "endTime": "2022-10-13 15:13:31", "pass_num": 19, "fail_num": 0, "error_num": 1, "notrun_num": 0, "errorCode": 1 }, { "id": 9909, "plan": "882", "startTime": "2022-10-13 15:10:02", "endTime": "2022-10-13 15:10:07", "pass_num": 19, "fail_num": 1, "error_num": 0, "notrun_num": 0, "errorCode": 1 } ], "page": 1, "total": 1 } }
二、添加断言
1、断言
断言json返回值中,第二个data列表中,最新一个结果中,pass_num的值为20
// 定义变量jsonData,保存响应结果到该变量中 var jsonData = JSON.parse(responseBody);
// 判断data列表中第一条数据pass_num的值是否为20 tests["检查测试计划通过数为20"] = jsonData.data.data[0].pass_num === 20;
![](/i/l/?n=22&i=blog/2337990/202210/2337990-20221013170918407-604116195.png)