0
0
Postmantesting~10 mins

Environment variables in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access an environment variable named 'api_key' in Postman test script.

Postman
const apiKey = pm.environment.get('[1]');
Drag options to blanks, or click blank then click option'
Aapi_key
BAPI_KEY
Capikey
Dkey_api
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or different spelling for the variable name.
Trying to access variables without using pm.environment.get().
2fill in blank
medium

Complete the code to set an environment variable 'session_id' to '12345' in Postman test script.

Postman
pm.environment.[1]('session_id', '12345');
Drag options to blanks, or click blank then click option'
Aget
Bset
Cunset
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' to assign a value.
Using methods that remove variables instead of setting them.
3fill in blank
hard

Fix the error in the code to remove an environment variable named 'token' in Postman test script.

Postman
pm.environment.[1]('token');
Drag options to blanks, or click blank then click option'
Aclear
Bremove
Cdelete
Dunset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' or 'remove' which are not valid Postman methods.
Using 'clear' which removes all variables, not one.
4fill in blank
hard

Fill both blanks to check if environment variable 'user_id' exists and log its value in Postman test script.

Postman
if (pm.environment.[1]('user_id')) {
  console.log(pm.environment.[2]('user_id'));
}
Drag options to blanks, or click blank then click option'
Aget
Bset
Cunset
Dhas
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check existence instead of 'has'.
Using 'set' or 'unset' incorrectly in this context.
5fill in blank
hard

Fill all three blanks to update environment variable 'count' by incrementing its value by 1 in Postman test script.

Postman
let count = parseInt(pm.environment.[1]('count') || '0');
count = count [2] 1;
pm.environment.[3]('count', count.toString());
Drag options to blanks, or click blank then click option'
Aget
B+
Cset
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Forgetting to convert the number to string before setting.
Using wrong methods like 'unset' or 'has' in this context.