0
0
Postmantesting~10 mins

Dynamic URL building in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that a dynamic URL is correctly built using variables in Postman and that the API responds with status 200.

Test Code - Postman
Postman
pm.test("Dynamic URL builds correctly and returns 200", function () {
    const baseUrl = pm.environment.get("baseUrl");
    const userId = pm.environment.get("userId");
    const endpoint = `/users/${userId}/profile`;
    const fullUrl = baseUrl + endpoint;

    pm.sendRequest(fullUrl, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('status', 200);
    });
});
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test script execution begins-PASS
2Retrieve 'baseUrl' and 'userId' from environment variablesVariables baseUrl='https://api.example.com', userId='12345' loaded-PASS
3Build dynamic endpoint string using userIdendpoint='/users/12345/profile' constructed-PASS
4Concatenate baseUrl and endpoint to form fullUrlfullUrl='https://api.example.com/users/12345/profile'-PASS
5Send HTTP GET request to fullUrlRequest sent to 'https://api.example.com/users/12345/profile'-PASS
6Check that error is null and response status code is 200Response received with status 200Assert err is null and res.status equals 200PASS
Failure Scenario
Failing Condition: The dynamic URL is incorrect or the API returns an error status
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the dynamic URL?
AIt correctly builds the URL using variables and gets a 200 response
BIt checks if the URL contains query parameters
CIt verifies the URL is hardcoded
DIt tests the POST method on the URL
Key Result
Always use environment variables to build dynamic URLs in Postman to make tests flexible and reusable.