0
0
Postmantesting~10 mins

Nested object assertions in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to an API endpoint and verifies nested objects in the JSON response. It checks that the user details and address fields exist and have expected values.

Test Code - Postman
Postman
pm.test("Verify nested user details and address", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('user');
    pm.expect(jsonData.user).to.have.property('name', 'John Doe');
    pm.expect(jsonData.user).to.have.property('address');
    pm.expect(jsonData.user.address).to.include({
        city: 'New York',
        zip: '10001'
    });
});
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test runner is ready-PASS
2Send GET request to API endpointAPI server receives request and sends JSON response with user details-PASS
3Parse JSON response bodyResponse body parsed into jsonData object-PASS
4Check if 'user' property exists in jsonDatajsonData contains 'user' objectjsonData has property 'user'PASS
5Check if 'name' property of user equals 'John Doe'jsonData.user.name is 'John Doe'jsonData.user.name === 'John Doe'PASS
6Check if 'address' property exists in user objectjsonData.user.address object existsjsonData.user has property 'address'PASS
7Check if 'city' and 'zip' in address match expected valuesjsonData.user.address.city is 'New York' and zip is '10001'jsonData.user.address includes {city: 'New York', zip: '10001'}PASS
8Test ends with all assertions passingAll nested object assertions verified successfully-PASS
Failure Scenario
Failing Condition: The 'address' property is missing or has incorrect values in the response JSON
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first in the JSON response?
AIf the 'city' value is 'New York'
BIf the 'user' property exists
CIf the 'address' property exists
DIf the response status is 404
Key Result
When testing nested JSON objects, verify each nested property step-by-step to catch missing or incorrect data clearly.