Verify API response changes when switching Postman environments
Preconditions (4)
✅ Expected Result: The response status code and body should differ between 'Development' and 'Production' environments, reflecting the different baseUrl values.
pm.test('Status code is 200', function () { pm.response.to.have.status(200); }); pm.test('Response body contains environment info', function () { const responseJson = pm.response.json(); const env = pm.environment.name; pm.expect(responseJson.environment).to.eql(env); });
The first test checks that the response status code is 200, which means the request was successful.
The second test parses the JSON response and verifies that the 'environment' field matches the current environment name. This confirms that the request used the correct baseUrl from the environment.
These tests should be run separately with the 'Development' and 'Production' environments selected in Postman to verify environment switching.
Now add data-driven testing by running the same test with three different environments: Development, Staging, and Production.
Dev: baseUrl=https://dev.api.comProd: baseUrl=https://api.com{{baseUrl}}/usersTest: apiUrl=https://test.api.com, token=abc123Live: apiUrl=https://live.api.com, token=xyz789Pass the test and this pattern moves unknown