0
0
Postmantesting~10 mins

JSON value assertions in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to a sample API endpoint and verifies that the JSON response contains specific values. It checks that the user ID is 1 and the username is 'Bret'.

Test Code - Postman
Postman
pm.test("Verify JSON response values", () => {
    const jsonData = pm.response.json();
    pm.expect(jsonData.id).to.eql(1);
    pm.expect(jsonData.username).to.eql("Bret");
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Send GET request to https://jsonplaceholder.typicode.com/users/1Request sent, waiting for response-PASS
2Receive JSON response with user dataResponse body contains JSON with fields including id and username-PASS
3Parse JSON response to extract fieldsjsonData object created with response values-PASS
4Assert that jsonData.id equals 1jsonData.id is 1pm.expect(jsonData.id).to.eql(1)PASS
5Assert that jsonData.username equals 'Bret'jsonData.username is 'Bret'pm.expect(jsonData.username).to.eql("Bret")PASS
Failure Scenario
Failing Condition: The JSON response contains a different user ID or username than expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the JSON response?
AThat the JSON response is empty
BThat the response status is 404
CThat the user ID is 1 and username is 'Bret'
DThat the user email is 'Bret@example.com'
Key Result
Always verify specific JSON values in API responses to ensure the API returns correct data, using clear and direct assertions.