0
0
Postmantesting~10 mins

Environment variables in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the Postman environment variable baseUrl is correctly used to send a GET request and verifies the response status code is 200.

Test Code - Postman
Postman
pm.test("Status code is 200", function () {
    pm.sendRequest({
        url: pm.environment.get("baseUrl") + "/api/users",
        method: 'GET'
    }, function (err, res) {
        pm.expect(res).to.have.property('status', 200);
    });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test runner is ready to execute the test script-PASS
2Retrieve environment variable 'baseUrl'Environment variable 'baseUrl' is set, e.g., 'https://reqres.in'Check that 'baseUrl' is not null or emptyPASS
3Send GET request to 'https://reqres.in/api/users'Request sent to the server using the URL constructed from environment variable-PASS
4Receive response from serverServer responds with HTTP status code 200 and user data JSONVerify response status code equals 200PASS
5Assertion checks pass confirming status code is 200Test runner logs success for the assertionpm.expect(res).to.have.property('status', 200)PASS
Failure Scenario
Failing Condition: Environment variable 'baseUrl' is missing or incorrect, or server returns status code other than 200
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify using the environment variable?
AIt checks if the environment variable contains user data
BIt tests if the environment variable is empty
CIt verifies the response status code from the URL built using the environment variable
DIt verifies the request method is POST
Key Result
Always use environment variables to make your tests flexible and reusable across different environments without changing the test code.