Test Overview
This test verifies that a dynamic URL is correctly built using variables in Postman and that the API responds with status 200.
This test verifies that a dynamic URL is correctly built using variables in Postman and that the API responds with status 200.
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); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test script execution begins | - | PASS |
| 2 | Retrieve 'baseUrl' and 'userId' from environment variables | Variables baseUrl='https://api.example.com', userId='12345' loaded | - | PASS |
| 3 | Build dynamic endpoint string using userId | endpoint='/users/12345/profile' constructed | - | PASS |
| 4 | Concatenate baseUrl and endpoint to form fullUrl | fullUrl='https://api.example.com/users/12345/profile' | - | PASS |
| 5 | Send HTTP GET request to fullUrl | Request sent to 'https://api.example.com/users/12345/profile' | - | PASS |
| 6 | Check that error is null and response status code is 200 | Response received with status 200 | Assert err is null and res.status equals 200 | PASS |