邮递员-断言JSON响应中哪里有重复的部分 [英] Postman - asserting where there are duplicate sections in JSON response
本文介绍了邮递员-断言JSON响应中哪里有重复的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的JSON响应.我想编写一个测试,断言该成本= 1.000,其中provider = Apple.由于成本在响应中不断重复,因此我很挣扎.我将如何处理?谢谢.
This is my JSON response. I am wanting to write a test that asserts that cost = 1.000 where provider = Apple. As cost is repeated in the response, I'm struggling. How would I go about this? Thanks.
[
{
"provider": "Apple",
"cost": 1.000,
"active": true,
"total": false
},
{
"provider": "Banana",
"cost": 0.000,
"active": true,
"total": false
},
{
"provider": "Grape",
"cost": 0.000,
"active": true,
"total": false
}
]
推荐答案
您可以编写一个测试,循环遍历响应中的每个对象,如果对象中包含Apple值,则检查 cost
值 provider
键:
You can write a test which loops through each object in the response, checks the cost
value if the object contains the Apple value in the provider
key:
let jsonData = pm.response.json()
pm.test('Check the price of the Apple', () => {
_.each(jsonData, (item) => {
if(item.provider === 'Apple') {
pm.expect(item.cost).to.equal(1.000)
}
})
})
这篇关于邮递员-断言JSON响应中哪里有重复的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文