0
0
Postmantesting~10 mins

Local variables in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a local variable set within a Postman request script is correctly assigned and used in an assertion to verify the response status code.

Test Code - Postman
Postman
pm.test("Status code is 200", function () {
    let expectedStatus = 200; // local variable
    pm.response.to.have.status(expectedStatus);
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test script starts executionPostman request has completed and response is available-PASS
2Local variable 'expectedStatus' is assigned the value 200Variable 'expectedStatus' holds 200 within the test function scope-PASS
3Assertion checks if response status equals 'expectedStatus' (200)Response status code is 200pm.response.to.have.status(expectedStatus)PASS
4Test completes successfullyTest result recorded as pass-PASS
Failure Scenario
Failing Condition: Response status code is not 200
Execution Trace Quiz - 3 Questions
Test your understanding
What does the local variable 'expectedStatus' represent in the test?
AThe expected HTTP status code to verify
BThe actual response status code
CThe response body content
DThe request URL
Key Result
Using local variables in test scripts helps keep assertions clear and maintainable by avoiding hard-coded values.