0
0
Postmantesting~20 mins

Variable scope and precedence in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Variable Scope Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Variable Scope in Postman

In Postman, variables can exist at different scopes: Global, Collection, Environment, and Local (within a request). Which variable scope has the highest precedence when resolving a variable name during a request execution?

AGlobal variables
BEnvironment variables
CCollection variables
DLocal variables
Attempts:
2 left
💡 Hint

Think about which variable is closest to the request itself.

Predict Output
intermediate
2:00remaining
Output of Variable Resolution in Postman Script

Given the following Postman pre-request script and variable scopes, what will be the value of pm.variables.get('token') during the request execution?

Global variable token = "global123"

Environment variable token = "env456"

Collection variable token = "col789"

Pre-request script:

Postman
pm.variables.set('token', 'local000');
console.log(pm.variables.get('token'));
A"local000"
B"env456"
C"col789"
D"global123"
Attempts:
2 left
💡 Hint

Variables set in the script override other scopes.

assertion
advanced
2:00remaining
Correct Assertion for Variable Value in Postman Test

You want to assert that the variable userId used in your request is the environment variable value, not a local or global one. Which assertion correctly verifies this in the test script?

Apm.test('userId is environment variable', () => pm.expect(pm.variables.get('userId')).to.eql(pm.environment.get('userId')));
Bpm.test('userId is environment variable', () => pm.expect(pm.variables.get('userId')).to.eql(pm.global.get('userId')));
Cpm.test('userId is environment variable', () => pm.expect(pm.environment.get('userId')).to.eql(pm.variables.get('userId')));
Dpm.test('userId is environment variable', () => pm.expect(pm.environment.get('userId')).to.eql(pm.global.get('userId')));
Attempts:
2 left
💡 Hint

Remember that pm.variables.get() returns the variable value with precedence applied.

🔧 Debug
advanced
2:00remaining
Debugging Variable Precedence Issue in Postman

You have a collection variable apiKey set to "colKey" and an environment variable apiKey set to "envKey". Your request script uses pm.variables.get('apiKey') but always returns "colKey" instead of "envKey". What is the most likely reason?

ALocal variables override all, so a local variable named "apiKey" must exist with value "colKey".
BEnvironment variables have higher precedence than collection variables, so "envKey" should be returned but there's a bug.
CCollection variables have higher precedence than environment variables, so "colKey" is returned.
DGlobal variables override both collection and environment variables, causing "colKey" to appear.
Attempts:
2 left
💡 Hint

Check the Postman variable precedence order.

framework
expert
3:00remaining
Order of Variable Resolution in Postman

Arrange the following Postman variable scopes in the order Postman uses to resolve a variable name, from highest precedence to lowest.

A1, 2, 3, 4
B4, 3, 2, 1
C3, 4, 2, 1
D2, 3, 4, 1
Attempts:
2 left
💡 Hint

Think about which variables are closest to the request execution context.