Test Overview
This test checks if the Postman environment variable baseUrl is correctly used to send a GET request and verifies the response status code is 200.
This test checks if the Postman environment variable baseUrl is correctly used to send a GET request and verifies the response status code is 200.
pm.test("Status code is 200", function () { pm.sendRequest({ url: pm.environment.get("baseUrl") + "/api/users", method: 'GET' }, function (err, res) { pm.expect(res).to.have.property('status', 200); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready to execute the test script | — | PASS |
| 2 | Retrieve environment variable 'baseUrl' | Environment variable 'baseUrl' is set, e.g., 'https://reqres.in' | Check that 'baseUrl' is not null or empty | PASS |
| 3 | Send GET request to 'https://reqres.in/api/users' | Request sent to the server using the URL constructed from environment variable | — | PASS |
| 4 | Receive response from server | Server responds with HTTP status code 200 and user data JSON | Verify response status code equals 200 | PASS |
| 5 | Assertion checks pass confirming status code is 200 | Test runner logs success for the assertion | pm.expect(res).to.have.property('status', 200) | PASS |
token to abc123 in a Postman test script?pm.environment.set(key, value) to set environment variables.pm.variables.set sets local variables, pm.environment.get is for getting values, and pm.setEnvironment is not a valid method.userId after execution?pm.environment.set('userId', 10);
pm.environment.set('userId', Number(pm.environment.get('userId')) + 5);userId to 10.userId (10), adds 5, and sets it back, so userId becomes 15.sessionId but it does not work:pm.environment.delete('sessionId');pm.environment.unset(key) to remove environment variables.pm.environment.delete() is not a valid method, so it does not remove the variable.dev and prod. Which is the best way to use environment variables to switch the base URL without changing the request code?baseUrl variables allows easy switching without code changes.Pass the test and this pattern moves unknown