Test Overview
This test checks how Postman uses variables from different scopes (global, collection, environment, local) and verifies that the variable with the highest precedence is used in the request.
This test checks how Postman uses variables from different scopes (global, collection, environment, local) and verifies that the variable with the highest precedence is used in the request.
pm.test("Variable scope and precedence test", function () { // Set variables in different scopes pm.globals.set("var1", "globalValue"); pm.collectionVariables.set("var1", "collectionValue"); pm.environment.set("var1", "environmentValue"); pm.variables.set("var1", "localValue"); // Access variable in test const resolvedVar = pm.variables.get("var1"); // Assert that the local variable has highest precedence pm.expect(resolvedVar).to.eql("localValue"); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test script execution begins | - | PASS |
| 2 | Set global variable 'var1' to 'globalValue' | Global variables include var1=globalValue | - | PASS |
| 3 | Set collection variable 'var1' to 'collectionValue' | Collection variables include var1=collectionValue | - | PASS |
| 4 | Set environment variable 'var1' to 'environmentValue' | Environment variables include var1=environmentValue | - | PASS |
| 5 | Set local variable 'var1' to 'localValue' | Local variables include var1=localValue | - | PASS |
| 6 | Retrieve variable 'var1' using pm.variables.get() | Variable resolved to 'localValue' due to precedence rules | Check if resolved variable equals 'localValue' | PASS |
| 7 | Test ends | Test completed successfully | - | PASS |