1
Recebo como resposta de uma requisição, o seguinte response:
"data": [
{
"id": 148,
"name": "Amrita Naik",
"email": "[email protected]",
"gender": "Female",
"status": "Inactive",
"created_at": "2021-01-25T03:50:06.849+05:30",
"updated_at": "2021-01-25T03:50:06.849+05:30"
},
{
"id": 156,
"name": "Dron Naik",
"email": "[email protected]",
"gender": "Male",
"status": "Active",
"created_at": "2021-01-25T03:50:06.975+05:30",
"updated_at": "2021-01-25T03:50:06.975+05:30"
},
{
"id": 178,
"name": "Rukmin Naik",
"email": "[email protected]",
"gender": "Male",
"status": "Active",
"created_at": "2021-01-25T03:50:07.351+05:30",
"updated_at": "2021-01-25T03:50:07.351+05:30"
},
I need to validate that all name fields have the name "Naik". Although my test passes, I can’t check, as it doesn’t print anything on the Postman console. Here’s what I tried to do:
pm.test("Deve validar o nome", function () {
const jsonData = JSON.parse(responseBody);
for(var i = 0; i < jsonData.length; i++) {
console.log(data[i].name);
}
pm.expect(jsonData.data[i].name).to.include("Naik");
});
Thank you! I was able to solve it as follows: pm.test("Must validate the name", Function() { var jsonData = pm.response.json(); for (var i = 0; i < jsonData.data.length; i++) { var obj = jsonData.data[i].name; console.log(obj); pm.expect(obj).to..(include"Naik"); } }); So all names containing the name "Naik" are validated.
– babi