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.
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.
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); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to the API endpoint | Postman sends the request and waits for response | - | PASS |
| 2 | Check that response status code is 200 | Response received with status code 200 | Verify pm.response.to.have.status(200) | PASS |
| 3 | Extract response body as text | Response body is available as string | - | PASS |
| 4 | Save response body to environment variable 'savedResponse' | Environment variable 'savedResponse' is set with response text | - | PASS |
| 5 | Verify saved environment variable matches response body | Environment variable value equals response body text | pm.expect(pm.environment.get('savedResponse')).to.eql(responseBody) | PASS |