0
0
Postmantesting~20 mins

Variable assignment in flows in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Variable assignment in Postman pre-request script
What will be the value of the environment variable token after running this pre-request script in Postman?
Postman
pm.environment.set('token', 'initial');
if (pm.response && pm.response.code === 200) {
  pm.environment.set('token', 'updated');
} else {
  pm.environment.set('token', 'failed');
}
A"failed"
B"initial"
C"updated"
Dundefined
Attempts:
2 left
💡 Hint
Remember that pre-request scripts run before the request is sent, so pm.response is not yet available.
assertion
intermediate
2:00remaining
Correct assertion for variable assignment in Postman test script
Which assertion correctly verifies that the global variable userId has been assigned the value 12345 in a Postman test script?
Apm.test('userId is 12345', () => pm.globals.get('userId') === '12345');
Bpm.test('userId is 12345', () => pm.expect(pm.globals.get('userId')).to.eql('12345'));
Cpm.test('userId is 12345', () => pm.globals.userId === 12345);
Dpm.test('userId is 12345', () => pm.expect(pm.globals.userId).to.equal(12345));
Attempts:
2 left
💡 Hint
Use pm.expect with pm.globals.get() to access global variables properly.
🔧 Debug
advanced
2:00remaining
Debugging variable assignment in Postman flow
Given this Postman test script, why does the variable sessionId remain undefined after the request?
Postman
if (pm.response.code === 200) {
  pm.variables.set('sessionId', pm.response.json().session);
}
console.log(pm.variables.get('sessionId'));
ABecause <code>pm.variables.set</code> requires a third argument to persist the variable.
BBecause <code>pm.response.code</code> is undefined in test scripts.
CBecause <code>pm.response.json()</code> is not a valid method to parse JSON response.
DBecause <code>pm.variables</code> only stores variables for the current request and is not persisted between requests.
Attempts:
2 left
💡 Hint
Consider the scope and lifetime of pm.variables compared to environment or global variables.
🧠 Conceptual
advanced
2:00remaining
Understanding variable scopes in Postman flows
Which statement correctly describes the difference between pm.variables, pm.environment, and pm.globals in Postman?
A<code>pm.variables</code> are temporary for the current request, <code>pm.environment</code> variables persist per environment, and <code>pm.globals</code> persist globally across all environments.
B<code>pm.variables</code> persist globally, <code>pm.environment</code> are temporary, and <code>pm.globals</code> persist per environment.
C<code>pm.variables</code> and <code>pm.environment</code> are the same, but <code>pm.globals</code> are temporary.
D<code>pm.variables</code> persist per environment, <code>pm.environment</code> persist globally, and <code>pm.globals</code> are temporary.
Attempts:
2 left
💡 Hint
Think about how long each variable type lasts and where it is accessible.
framework
expert
3:00remaining
Postman flow variable assignment and test execution order
In a Postman collection run, which sequence correctly describes when variables are assigned and accessible during the flow?
AVariables set in pre-request scripts are only available after the entire collection run finishes; test scripts run before pre-request scripts.
BTest scripts run before the request; then pre-request scripts run; then the request is sent; variables set in test scripts are not saved.
CPre-request scripts run first and can set variables; then the request is sent; then test scripts run and can update variables; environment and global variables persist between requests.
DRequests run first; then pre-request scripts run; then test scripts run; variables set in pre-request scripts are not accessible in test scripts.
Attempts:
2 left
💡 Hint
Recall the order of execution in Postman: pre-request script, request, test script.