postman】用postman验证接口是否返回某字段?

2020-09-21 17:41发布

1条回答

接口返回:
{
"data": [
{
"word": "上海",
"List": [
{
"word": "景点",
"type": "sight"
},
{
"word": "酒店",
"type": "hotel"
}
],
},
}
需要验证接口List中是否返回type字段(不需要验证值是否正确,只要验证是否返回该字段)


Tests中脚本:
var jsonData = pm.response.json();

pm.test("type字段检查", function () {
length = jsonData.data[0].List.length;
console.log(length);
for(i=0;i
console.log(jsonData.data[0].List[i]);
pm.expect(jsonData.data[0].List[i]).to.include("type");
}
});

执行后报错:

相关问题推荐

  • 回答 3

    1、Postman最早是作用chrome浏览器插件存在的,所以,你可以到chrome商店搜索下载安装,因为重所周知的原因,所以,大家都会找别人共享的postman插件文件来安装。由于2018年初Chrome停止对Chrome应用程序的支持。2、Postman提供了独立的安装包,不再依赖于Chr...

  • 回答 3
    已采纳

      Postman其实就是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件。  用处:采用postman 工具进行接口的功能验证,             可生成规范接口文档给予前端工程师进行使用,从而达到前后端交流。...

没有解决我的问题,去提问