Challenge - 5 Problems
Postman Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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'); }
Attempts:
2 left
💡 Hint
Remember that pre-request scripts run before the request is sent, so
pm.response is not yet available.✗ Incorrect
In a pre-request script,
pm.response is undefined because the request has not been sent yet. Therefore, the if condition is false, and the variable token is set to "failed".❓ assertion
intermediate2: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?Attempts:
2 left
💡 Hint
Use
pm.expect with pm.globals.get() to access global variables properly.✗ Incorrect
Option B uses
pm.expect to assert that the global variable userId (accessed via pm.globals.get('userId')) equals the string '12345'. This is the correct way to assert variable values in Postman test scripts.🔧 Debug
advanced2: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'));
Attempts:
2 left
💡 Hint
Consider the scope and lifetime of
pm.variables compared to environment or global variables.✗ Incorrect
pm.variables stores variables only for the current request execution and does not persist them between requests. To keep sessionId for later requests, use pm.environment.set or pm.globals.set.🧠 Conceptual
advanced2:00remaining
Understanding variable scopes in Postman flows
Which statement correctly describes the difference between
pm.variables, pm.environment, and pm.globals in Postman?Attempts:
2 left
💡 Hint
Think about how long each variable type lasts and where it is accessible.
✗ Incorrect
pm.variables exist only during the current request execution and are not saved. pm.environment variables are saved per environment and persist across requests. pm.globals variables are saved globally and accessible in all environments.❓ framework
expert3: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?
Attempts:
2 left
💡 Hint
Recall the order of execution in Postman: pre-request script, request, test script.
✗ Incorrect
Postman executes pre-request scripts before sending the request, allowing variable assignment before the request. After the request, test scripts run and can update variables. Environment and global variables persist between requests and across the collection run.