0
0
Postmantesting~10 mins

Variable assignment in flows 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 assign a variable named userId with the value 12345 in Postman script.

Postman
pm.variables.set('userId', [1]);
Drag options to blanks, or click blank then click option'
A"userId"
B12345
C'12345'
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string value.
Using variable name instead of value.
2fill in blank
medium

Complete the code to retrieve the variable sessionToken from Postman environment variables.

Postman
const token = pm.environment.get([1]);
Drag options to blanks, or click blank then click option'
AsessionToken
B'sessionToken'
C"token"
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the variable name.
Using a different variable name.
3fill in blank
hard

Fix the error in the code to correctly set a global variable count to 10.

Postman
pm.globals.set('count', [1]);
Drag options to blanks, or click blank then click option'
A10
B"count"
C'10'
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes making them strings.
Using variable name instead of value.
4fill in blank
hard

Fill both blanks to create a local variable status with value active and then retrieve it.

Postman
pm.variables.set([1], [2]);
const currentStatus = pm.variables.get('status');
Drag options to blanks, or click blank then click option'
A'status'
B'active'
Cstatus
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes for variable name or value.
Using variable names without quotes.
5fill in blank
hard

Fill all three blanks to set an environment variable userRole to admin, then get it and check if it equals admin.

Postman
pm.environment.set([1], [2]);
const role = pm.environment.get('userRole');
pm.test('Role is admin', () => pm.expect(role).to.eql([3]));
Drag options to blanks, or click blank then click option'
A'userRole'
B'admin'
C"admin"
Dadmin
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting variable names or values.
Using unquoted values in the test assertion.