In Postman, where are global variables accessible?
Think about variables that are shared everywhere in Postman.
Global variables in Postman are accessible across all collections and requests within the workspace, unlike environment variables which are limited to a specific environment.
What will be the output of the following Postman test script?
pm.globals.set('token', 'abc123'); const token = pm.globals.get('token'); console.log(token);
Consider what value is stored and then retrieved.
The script sets the global variable 'token' to 'abc123' and then retrieves it. The console.log will output 'abc123'.
Which assertion correctly verifies that the global variable 'userId' equals '42' in a Postman test script?
const userId = pm.globals.get('userId');Remember the type of the value returned by pm.globals.get.
pm.globals.get returns a string, so the assertion must compare to the string '42' using .to.equal().
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?
Check spelling carefully in both scripts.
If the variable name is misspelled in the Tests script, pm.globals.get will return undefined because it looks for a different variable.
Which approach is best to avoid conflicts and ensure maintainability when using global variables across multiple Postman collections?
Think about how to prevent variable name clashes.
Prefixing global variable names with collection-specific identifiers helps prevent conflicts and improves clarity when multiple collections use global variables.