Question:
I am trying to verify the first name is equal what is expected.
I have tried:
pm.test(âPerson is CHAXXXXXâ, () => {
const responseJson = pm.response.json();
pm.expect(responseJson.validAccounts[0].firstName).to.eql(âCHAXXXXXâ);
});
Result - Person is CHAXXXXX | TypeError: Cannot read property â0â of undefined
This is the response body
{
âsytemResponseâ: {
âresponseCodeâ: 200,
âresponseDescriptionâ: âOKâ
},
âresponseâ: {
âvalidAccountsâ: [
{
âfirstNameâ: âCHAXXXXXâ,
âaccountNumberâ: â123â
},
{
âfirstNameâ: âCHAXXXXXâ,
âaccountNumberâ: â456â
}
],
âvalidationResultâ: {
âisValidâ: true,
âresultCountâ: 2,
âvalidationResultDescriptionâ: âSuccessâ
}
}
}
w4dd325
(w4dd325)
2
Hi @automationtester2496
On first glance I think your assertion should be;
pm.expect(responseJson.response.validAccounts[0].firstName).to.eql(âCHAXXXXXâ);
responseJson is holding the entire response, but there is a âresponseâ object inside the JSON response (hope that makes sense).
Thank you very much that is the solution.
1 Like
@w4dd325 is there anyway to loop through the objects in the response body, to solve the following issue?