Test Overview
This test verifies that a global variable in Postman is set correctly and can be accessed in a subsequent request. It checks that the variable value matches the expected string.
This test verifies that a global variable in Postman is set correctly and can be accessed in a subsequent request. It checks that the variable value matches the expected string.
pm.test("Set and verify global variable", function () { pm.globals.set("userToken", "abc123token"); const token = pm.globals.get("userToken"); pm.expect(token).to.eql("abc123token"); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test script starts execution in Postman Sandbox | Postman test environment ready to run script | - | PASS |
| 2 | Set global variable 'userToken' to 'abc123token' using pm.globals.set | Global variables now include userToken = 'abc123token' | - | PASS |
| 3 | Retrieve global variable 'userToken' using pm.globals.get | Variable 'token' assigned value 'abc123token' | - | PASS |
| 4 | Assert that retrieved token equals 'abc123token' using pm.expect | Assertion compares 'abc123token' to 'abc123token' | pm.expect(token).to.eql('abc123token') | PASS |
| 5 | Test script completes successfully | Test result recorded as pass | - | PASS |