0
0
Postmantesting~20 mins

Collection variables in Postman - Practice Problems & Coding Challenges

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

In Postman, you have a collection variable named api_key set to 12345. You also have an environment variable with the same name api_key set to abcde. When you run a request inside this collection, which api_key value will Postman use?

AThe environment variable value <code>abcde</code> will be used because environment variables have higher priority than collection variables.
BPostman will randomly pick either <code>12345</code> or <code>abcde</code> each time the request runs.
CPostman will throw an error because variables with the same name cannot exist in collection and environment scopes.
DThe collection variable value <code>12345</code> will be used because collection variables override environment variables.
Attempts:
2 left
💡 Hint

Remember that Postman uses a specific order to resolve variables, and environment variables have a higher priority than collection variables.

query_result
intermediate
2:00remaining
Output of Variable Resolution in Pre-request Script

Given the following pre-request script in a Postman collection:

pm.collectionVariables.set('token', 'xyz123');
const tokenValue = pm.variables.get('token');
console.log(tokenValue);

What will be printed in the Postman console when this script runs?

Anull
Bundefined
Cxyz123
DAn error is thrown because <code>pm.variables.get</code> cannot access collection variables.
Attempts:
2 left
💡 Hint

Check how pm.variables.get resolves variables from different scopes.

📝 Syntax
advanced
2:00remaining
Correct Syntax to Set a Collection Variable

Which of the following Postman scripts correctly sets a collection variable named userId to the value 789?

Apm.collectionVariables['userId'] = 789;
Bpm.collectionVariables.set(userId, '789');
Cpm.collectionVariables.set('userId' = '789');
Dpm.collectionVariables.set('userId', 789);
Attempts:
2 left
💡 Hint

Remember the method signature for setting collection variables requires a string key and a value.

optimization
advanced
2:00remaining
Efficiently Updating Multiple Collection Variables

You want to update three collection variables var1, var2, and var3 with new values 10, 20, and 30 respectively in a pre-request script. Which approach is the most efficient and correct?

ACreate an object with all variables and use a loop to set each variable with <code>pm.collectionVariables.set</code>.
BSet variables directly on <code>pm.collectionVariables</code> like properties, e.g., <code>pm.collectionVariables.var1 = 10</code>.
CUse <code>pm.collectionVariables.set</code> once with all variables as an object argument.
DCall <code>pm.collectionVariables.set</code> three times, once for each variable.
Attempts:
2 left
💡 Hint

Consider code readability and maintainability when updating multiple variables.

🔧 Debug
expert
2:00remaining
Debugging Collection Variable Persistence Issue

You set a collection variable sessionId in a test script using pm.collectionVariables.set('sessionId', 'abc123');. However, after the request finishes, the variable sessionId is not saved and disappears. What is the most likely reason?

AThe collection variable name <code>sessionId</code> is reserved and cannot be used.
BCollection variables set in test scripts are not saved persistently unless you explicitly save the collection.
CYou must use <code>pm.variables.set</code> instead of <code>pm.collectionVariables.set</code> to persist variables.
DCollection variables set in scripts are saved only if the Postman app is running in offline mode.
Attempts:
2 left
💡 Hint

Think about how Postman handles variable persistence and saving collections.