Test Overview
This test verifies that a dynamic URL is correctly built using variables in Postman and that the API responds with status 200.
Jump into concepts and practice - no test required
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 |
userId in a Postman URL?baseUrl set to https://api.example.com and the request URL {{baseUrl}}/users/{{userId}} with userId set to 42, what is the final URL sent by Postman?{{baseUrl}/users/{{userId}} in Postman, but the request fails. What is the likely error?{{baseUrl} missing a closing brace, which breaks variable substitution.env which can be dev or prod. Which URL correctly uses dynamic URL building to select the environment?