如果结果returns,如何在邮递员中验证而不考虑结果数量
How to verify in postman regardless of the number of results if the result returns
如何在 postman 中验证响应中的所有数据 returns id、firstname、lastname 等的结果数量
响应如下:
[
{
"id": 1,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 4
},
{
"id": 5,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 8
},
{
"id": 9,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 12
}
]
我想验证两件事:
1) 回复 returns id, first_name, last_name, email
2) 无论只有一个结果还是100个
,所有first_name都等于"Sebastian"
这是我尝试过的方法,但它只适用于一个结果:
const jsonData = pm.response.json();
pm.test('Has data', function() {
pm.expect(jsonData).to.have.property('first_name');
pm.expect(jsonData).to.have.property('last_name');
pm.expect(jsonData).to.have.property('email');
pm.expect(jsonData).to.have.property('id');
});
你可以试试这个:
pm.test("Has data",() => {
_.each(pm.response.json(), (item) => {
pm.expect(item.first_name).to.eql("Sebastian")
pm.expect(item).to.have.property('first_name')
pm.expect(item).to.have.property('last_name')
pm.expect(item).to.have.property('email')
pm.expect(item).to.have.property('id')
})
})
这将根据您提供的数据集工作。
如何在 postman 中验证响应中的所有数据 returns id、firstname、lastname 等的结果数量
响应如下:
[
{
"id": 1,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 4
},
{
"id": 5,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 8
},
{
"id": 9,
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com"
},
{
"first_name": "Sebastian",
"last_name": "Eschweiler",
"email": "sebastian@codingthesmartway.com",
"id": 12
}
]
我想验证两件事:
1) 回复 returns id, first_name, last_name, email
2) 无论只有一个结果还是100个
,所有first_name都等于"Sebastian"这是我尝试过的方法,但它只适用于一个结果:
const jsonData = pm.response.json();
pm.test('Has data', function() {
pm.expect(jsonData).to.have.property('first_name');
pm.expect(jsonData).to.have.property('last_name');
pm.expect(jsonData).to.have.property('email');
pm.expect(jsonData).to.have.property('id');
});
你可以试试这个:
pm.test("Has data",() => {
_.each(pm.response.json(), (item) => {
pm.expect(item.first_name).to.eql("Sebastian")
pm.expect(item).to.have.property('first_name')
pm.expect(item).to.have.property('last_name')
pm.expect(item).to.have.property('email')
pm.expect(item).to.have.property('id')
})
})
这将根据您提供的数据集工作。