0
0
Postmantesting~10 mins

Environment switching 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 select the active environment in Postman.

Postman
pm.environment.set('[1]', 'production');
Drag options to blanks, or click blank then click option'
Aenv
BcurrentEnv
CactiveEnvironment
DenvironmentName
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist in Postman scripts.
Confusing environment variables with environment names.
2fill in blank
medium

Complete the code to get the value of a variable from the current environment.

Postman
let apiUrl = pm.environment.get('[1]');
Drag options to blanks, or click blank then click option'
AapiUrl
BbaseUrl
Curl
Dendpoint
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined in the environment.
Confusing variable names with environment names.
3fill in blank
hard

Fix the error in the code to switch environment variables correctly.

Postman
pm.environment.[1]('token', '12345');
Drag options to blanks, or click blank then click option'
Aget
Bclear
Cunset
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of set to assign values.
Using unset or clear which remove variables.
4fill in blank
hard

Fill both blanks to correctly check if the current environment is 'staging' and set a variable.

Postman
if (pm.environment.get('[1]') === '[2]') {
  pm.environment.set('status', 'testing');
}
Drag options to blanks, or click blank then click option'
AenvironmentName
BcurrentEnv
Cstaging
Dproduction
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for environment name.
Mixing up environment names in the comparison.
5fill in blank
hard

Fill all three blanks to create a test that verifies the environment variable 'userId' exists and is not empty.

Postman
pm.test('User ID exists', function() {
  let userId = pm.environment.get('[1]');
  pm.expect(userId).to.[2].not.[3];
});
Drag options to blanks, or click blank then click option'
AuserId
Bbe
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Using incorrect assertion syntax.
Checking for undefined instead of null.