0
0
Postmantesting~10 mins

Variable assignment in flows in Postman - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Postman
Postman
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);
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test environment initialized-PASS
2Assign initial value 1 to variable 'counter' using pm.variables.setVariable 'counter' set to 1 in local scope-PASS
3Retrieve current value of 'counter' using pm.variables.getVariable 'counter' value is 1-PASS
4Increment 'counter' by 1 and assign back using pm.variables.setVariable 'counter' updated to 2-PASS
5Assert that 'counter' equals 2 using pm.expectVariable 'counter' value is 2pm.expect(pm.variables.get("counter")).to.eql(2)PASS
Failure Scenario
Failing Condition: Variable 'counter' is not updated correctly and remains 1 or undefined
Execution Trace Quiz - 3 Questions
Test your understanding
What does pm.variables.set("counter", 1) do in the test?
AReads the value of 'counter'
BAssigns the value 1 to the variable 'counter' in the current scope
CDeletes the variable 'counter'
DSends a request to update 'counter'
Key Result
Always verify that variables are correctly assigned and updated in your test flow to avoid false test passes or failures.