0
0
Postmantesting~10 mins

Variable scope and precedence 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 the global variable in Postman test script.

Postman
pm.globals.set('token', 'abc123');
const tokenValue = pm.[1].get('token');
Drag options to blanks, or click blank then click option'
Aenvironment
Bglobals
Cvariables
DcollectionVariables
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.environment.get instead of pm.globals.get
Trying to access variables without pm object
2fill in blank
medium

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

Postman
pm.[1].set('userId', 'user_001');
Drag options to blanks, or click blank then click option'
Aenvironment
Bglobals
Cvariables
DcollectionVariables
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.globals.set instead of pm.environment.set
Using pm.variables.set which sets local variables
3fill in blank
hard

Fix the error in the code to correctly get a collection variable in Postman test script.

Postman
const apiKey = pm.[1].get('api_key');
Drag options to blanks, or click blank then click option'
AcollectionVariables
Benvironment
Cglobals
Dvariables
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.environment.get for collection variables
Using pm.globals.get for collection variables
4fill in blank
hard

Fill both blanks to correctly set and then get a local variable in Postman test script.

Postman
pm.variables.[1]('sessionId', 'sess_789');
const session = pm.variables.[2]('sessionId');
Drag options to blanks, or click blank then click option'
Aset
Bget
Cunset
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.unset to set a variable
Using pm.variables.clear to get a variable
5fill in blank
hard

Fill all three blanks to create a test that checks if the environment variable 'status' equals 'active'.

Postman
const status = pm.[1].get('status');
pm.test('Status is active', function () {
  pm.expect(status).to.[2]([3]);
});
Drag options to blanks, or click blank then click option'
Aenvironment
Bequal
C'active'
Dglobals
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.globals.get instead of pm.environment.get
Using pm.expect().to.be instead of pm.expect().to.equal
Not quoting the string 'active'