0
0
Postmantesting~20 mins

Global variables in Postman - Practice Problems & Coding Challenges

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

In Postman, where are global variables accessible?

AAcross all collections and requests in the current Postman workspace
BOnly within the current request and its scripts
COnly within the current collection
DOnly within the current environment
Attempts:
2 left
💡 Hint

Think about variables that are shared everywhere in Postman.

Predict Output
intermediate
2:00remaining
Output of Setting and Getting a Global Variable

What will be the output of the following Postman test script?

Postman
pm.globals.set('token', 'abc123');
const token = pm.globals.get('token');
console.log(token);
Aabc123
Bundefined
Cnull
DError: pm.globals is not defined
Attempts:
2 left
💡 Hint

Consider what value is stored and then retrieved.

assertion
advanced
2:00remaining
Correct Assertion for Global Variable Value

Which assertion correctly verifies that the global variable 'userId' equals '42' in a Postman test script?

Postman
const userId = pm.globals.get('userId');
Apm.test('User ID is 42', () => pm.expect(userId).to.eql(42));
Bpm.test('User ID is 42', () => pm.expect(userId).to.be(42));
Cpm.test('User ID is 42', () => pm.expect(userId).to.equal('42'));
Dpm.test('User ID is 42', () => pm.expect(userId).toBe('42'));
Attempts:
2 left
💡 Hint

Remember the type of the value returned by pm.globals.get.

🔧 Debug
advanced
2:00remaining
Debugging Global Variable Not Updating

A tester sets a global variable in the Pre-request Script using pm.globals.set('session', 'xyz'), but in the Tests script, pm.globals.get('session') returns undefined. What is the most likely cause?

AThe variable was deleted before the Tests script runs
BGlobal variables cannot be set in Pre-request Scripts
CThe Tests script runs before the Pre-request Script
DThe variable name is misspelled in the Tests script
Attempts:
2 left
💡 Hint

Check spelling carefully in both scripts.

framework
expert
2:00remaining
Best Practice for Managing Global Variables in Postman Collections

Which approach is best to avoid conflicts and ensure maintainability when using global variables across multiple Postman collections?

AUse generic global variable names like 'token' or 'id' for all collections
BPrefix global variable names with collection-specific identifiers, e.g., 'coll1_token'
CSet and delete global variables dynamically in each request without naming conventions
DAvoid using global variables and use only environment variables instead
Attempts:
2 left
💡 Hint

Think about how to prevent variable name clashes.