假设从调用返回的json主体包含一些动态键(即
{
"message": "search results matching criteria",
"permission": {
"261ef70e-0a95-4967-b078-81e657e32699": {
"device": {
"read:own": [
"*"
]
},
"account": {
"read:own": [
"*"
]
},
"user": {
"read:own": [
"*"
]
}
}
}我可以很容易地验证下面的json,尽管我在解决如何验证低于响应的动态guid级别的对象时遇到了很多麻烦。
pm.test("response body to have correct items", function () {
pm.expect(jsonData.message).to.eq("search results matching criteria");
pm.expect(jsonData).to.have.property('permission');
pm.expect(jsonData.permission).to.have.property(pm.variables.get("otherUserId"));});
理想情况下,希望验证对象的设备、帐户和用户级别。
有谁有什么建议吗?
我尝试了几种方法来引用otherUserId变量,但都不起作用。它要么没有解析变量,因此测试失败,因为它在json中查找一个名为otherUserId的级别,或者由于语法错误而无法运行测试。
发布于 2019-02-11 07:45:36
这是可行的:
pm.expect(jsonData.permission[pm.variables.get("otherUserId")]).to.have.property('device');https://stackoverflow.com/questions/54622261
复制相似问题