Test Overview
This test verifies that the API request correctly switches between different environments in Postman. It ensures the request URL changes according to the selected environment variables.
This test verifies that the API request correctly switches between different environments in Postman. It ensures the request URL changes according to the selected environment variables.
pm.test("Environment switching test", function () { // Get the base URL from environment variable const baseUrl = pm.environment.get("base_url"); // Check that the base URL is not empty pm.expect(baseUrl).to.not.be.empty; // Check that the request URL starts with the base URL pm.expect(pm.request.url.toString()).to.include(baseUrl); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts in Postman with selected environment 'Development' | Postman UI shows environment 'Development' active with base_url set to 'https://dev.api.example.com' | - | PASS |
| 2 | Send API request using the environment variable base_url | Request URL is 'https://dev.api.example.com/users', server responds with 200 OK | - | PASS |
| 3 | Run test script to verify base_url is set and used in request URL | Test script accesses pm.environment.get('base_url') and pm.request.url | Assert base_url is not empty and request URL includes base_url | PASS |
| 4 | Switch environment to 'Production' in Postman | Postman UI shows environment 'Production' active with base_url set to 'https://api.example.com' | - | PASS |
| 5 | Send API request again using new environment variable base_url | Request URL is 'https://api.example.com/users', server responds with 200 OK | - | PASS |
| 6 | Run test script again to verify base_url is updated and used in request URL | Test script accesses pm.environment.get('base_url') and pm.request.url | Assert base_url is not empty and request URL includes base_url | PASS |