Test Overview
This test checks that using variables in Postman requests avoids hardcoding values. It verifies that changing a variable updates the request dynamically without editing the request itself.
This test checks that using variables in Postman requests avoids hardcoding values. It verifies that changing a variable updates the request dynamically without editing the request itself.
pm.test("Request uses variable instead of hardcoded value", () => { const baseUrl = pm.environment.get("baseUrl"); pm.expect(baseUrl).to.be.a("string").and.not.empty; const requestUrl = pm.request.url.toString(); pm.expect(requestUrl).to.include(baseUrl); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts in Postman test script | Postman environment has variable 'baseUrl' set to 'https://api.example.com' | - | PASS |
| 2 | Retrieve 'baseUrl' variable from environment | Variable 'baseUrl' value is 'https://api.example.com' | Check that 'baseUrl' is a non-empty string | PASS |
| 3 | Get the full request URL from the current request | Request URL is 'https://api.example.com/users?id=123' | Verify that request URL includes the 'baseUrl' variable value | PASS |
| 4 | Test ends with all assertions passed | Request uses variable correctly, no hardcoded base URL | - | PASS |