0
0
Postmantesting~20 mins

Variable syntax ({{variable}}) in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script?

Given the following Postman test script, what will be the value of responseVar after execution?

pm.variables.set("userId", 123);
const responseVar = pm.variables.get("userId");
Postman
pm.variables.set("userId", 123);
const responseVar = pm.variables.get("userId");
Anull
B"userId"
Cundefined
D123
Attempts:
2 left
💡 Hint

Remember that pm.variables.set stores a variable and pm.variables.get retrieves its value.

assertion
intermediate
2:00remaining
Which assertion correctly checks if a variable {{token}} is not empty?

In a Postman test script, you want to assert that the variable {{token}} is not an empty string. Which assertion is correct?

Apm.expect(pm.variables.get('token')).to.not.be.empty;
Bpm.expect(pm.variables.get('token')).to.equal('');
Cpm.expect(pm.variables.get('token')).to.be.undefined;
Dpm.expect(pm.variables.get('token')).to.be.null;
Attempts:
2 left
💡 Hint

Think about how to check that a string is not empty using Postman assertions.

locator
advanced
2:00remaining
Which variable syntax correctly accesses an environment variable named 'sessionId' in Postman?

In Postman, you want to access the environment variable sessionId inside a test script. Which syntax is correct?

Apm.environment.get('sessionId')
Bpm.variables.get('sessionId')
C{{sessionId}}
Dpm.globals.get('sessionId')
Attempts:
2 left
💡 Hint

Remember that environment variables are accessed differently than local or global variables.

🔧 Debug
advanced
2:00remaining
Why does this Postman script fail to replace {{user}} in the request URL?

Consider this Postman request URL: https://api.example.com/users/{{user}}. The variable user is set in the collection variables. The test script contains:

pm.variables.set('user', 'alice');

Why does the URL not replace {{user}} with 'alice' when the request runs?

ABecause collection variables override local variables, so the URL uses the collection variable value.
BBecause the variable name 'user' is reserved and cannot be used.
CBecause pm.variables.set sets a local variable that does not affect URL variable substitution.
DBecause variable substitution only works with environment variables, not collection variables.
Attempts:
2 left
💡 Hint

Think about when variable substitution happens in Postman and which variable scopes affect it.

framework
expert
2:00remaining
In Postman, which variable scope has the highest priority during variable substitution?

Postman supports multiple variable scopes: global, environment, collection, and local (script). When Postman replaces variables like {{varName}} in a request, which scope does it check first?

ACollection variables
BLocal (script) variables
CEnvironment variables
DGlobal variables
Attempts:
2 left
💡 Hint

Consider the order Postman uses to resolve variables for substitution in requests.