Verify usage of collection variables in Postman requests
Preconditions (3)
✅ Expected Result: The request uses the collection variable 'baseUrl' correctly, the response status code is 200, and the response body contains the user id 123
pm.test('Status code is 200', function () { pm.response.to.have.status(200); }); const userId = 123; const responseJson = pm.response.json(); pm.test(`Response has user id ${userId}`, function () { pm.expect(responseJson.id).to.eql(userId); });
The first test checks that the response status code is 200 using pm.response.to.have.status(200). This confirms the request was successful.
Next, we parse the response body as JSON with pm.response.json(). We then assert that the id field in the response equals the expected user id (123) using pm.expect().to.eql().
We use pm.test() to group assertions with descriptive names, making the test report clear.
The request URL uses the collection variable {{baseUrl}} to avoid hardcoding the API base URL, which improves maintainability.
Now add data-driven testing by running the same request for user IDs 101, 123, and 150 using collection variables
collection variables in Postman?api_key inside a request URL in Postman?base_url set to https://api.test.com, what will be the full URL for this request?GET {{base_url}}/userstoken but your request still sends Authorization: Bearer {{token}} literally without replacing it. What is the likely cause?token was not saved properly -> Option Buser_id in a request body JSON like this:{ "id": "{{user_id}}", "action": "delete" }id as a number, not a string. How should you fix the request body to send user_id as a number?Pass the test and this pattern moves unknown