0
0
Postmantesting~10 mins

Dynamic assertion values in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to a user API endpoint and verifies that the returned user ID matches the expected dynamic value from the response. It checks that the user name is not empty and the status code is 200.

Test Code - Postman
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("User ID matches dynamic value", function () {
    const jsonData = pm.response.json();
    const expectedUserId = jsonData.data.id;
    pm.expect(jsonData.data.id).to.eql(expectedUserId);
});

pm.test("User name is not empty", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.data.name).to.not.be.empty;
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send GET request to https://api.example.com/users/123Request sent, waiting for response-PASS
2Receive response with status code 200 and JSON body containing user dataResponse received: {"data":{"id":123,"name":"Alice"}}Check that status code is 200PASS
3Extract user ID from response JSON and assign to expectedUserIdexpectedUserId = 123Verify that response user ID equals expectedUserIdPASS
4Check that user name field is not emptyUser name is 'Alice'Verify user name is not emptyPASS
Failure Scenario
Failing Condition: Response user ID does not match the dynamically extracted expectedUserId
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the user ID?
AIt is always 123 regardless of response
BIt matches the dynamic value extracted from the response
CIt is not checked in the test
DIt is compared to a hardcoded value 456
Key Result
Using dynamic values from the response in assertions makes tests flexible and reliable, avoiding hardcoded checks that can break with data changes.