0
0
Postmantesting~10 mins

Saving responses in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to an API endpoint and saves the response body into a Postman environment variable. It then verifies that the response status is 200 and that the saved response matches the actual response.

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

pm.test("Save response body to environment variable", function () {
    let responseBody = pm.response.text();
    pm.environment.set("savedResponse", responseBody);
    pm.expect(pm.environment.get("savedResponse")).to.eql(responseBody);
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Send GET request to the API endpointPostman sends the request and waits for response-PASS
2Check that response status code is 200Response received with status code 200Verify pm.response.to.have.status(200)PASS
3Extract response body as textResponse body is available as string-PASS
4Save response body to environment variable 'savedResponse'Environment variable 'savedResponse' is set with response text-PASS
5Verify saved environment variable matches response bodyEnvironment variable value equals response body textpm.expect(pm.environment.get('savedResponse')).to.eql(responseBody)PASS
Failure Scenario
Failing Condition: Response status is not 200 or environment variable is not set correctly
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the request?
AThat the response body is empty
BThat the environment variable is deleted
CThat the response status code is 200
DThat the request method is POST
Key Result
Always verify the response status before saving data, and confirm saved variables match the actual response to avoid false positives.