Test Overview
This test checks if a variable is correctly set in a Postman script and then used in a subsequent request. It verifies that the variable value is stored and accessible.
This test checks if a variable is correctly set in a Postman script and then used in a subsequent request. It verifies that the variable value is stored and accessible.
pm.test("Set and use environment variable", function () { pm.environment.set("userId", "12345"); let userId = pm.environment.get("userId"); pm.expect(userId).to.eql("12345"); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready to execute the script | - | PASS |
| 2 | Set environment variable 'userId' to '12345' using pm.environment.set | Environment variables now include userId = '12345' | - | PASS |
| 3 | Retrieve environment variable 'userId' using pm.environment.get | Variable userId retrieved with value '12345' | - | PASS |
| 4 | Assert that retrieved userId equals '12345' using pm.expect | Assertion compares expected '12345' with actual '12345' | pm.expect(userId).to.eql('12345') | PASS |
| 5 | Test ends successfully | Variable set and verified correctly | - | PASS |