Test Overview
This test checks if a variable is correctly assigned and updated during a Postman request flow. It verifies that the variable value changes as expected after the request runs.
This test checks if a variable is correctly assigned and updated during a Postman request flow. It verifies that the variable value changes as expected after the request runs.
pm.test("Variable assignment in flow", function () { // Assign initial value to variable pm.variables.set("counter", 1); // Simulate flow: increment variable let currentValue = pm.variables.get("counter"); pm.variables.set("counter", currentValue + 1); // Verify variable updated correctly pm.expect(pm.variables.get("counter")).to.eql(2); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test environment initialized | - | PASS |
| 2 | Assign initial value 1 to variable 'counter' using pm.variables.set | Variable 'counter' set to 1 in local scope | - | PASS |
| 3 | Retrieve current value of 'counter' using pm.variables.get | Variable 'counter' value is 1 | - | PASS |
| 4 | Increment 'counter' by 1 and assign back using pm.variables.set | Variable 'counter' updated to 2 | - | PASS |
| 5 | Assert that 'counter' equals 2 using pm.expect | Variable 'counter' value is 2 | pm.expect(pm.variables.get("counter")).to.eql(2) | PASS |