0
0
Postmantesting~10 mins

Why variables avoid hardcoding in Postman - Test Your Understanding

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

Complete the code to use a variable instead of hardcoding the URL.

Postman
pm.sendRequest({ url: [1], method: 'GET' }, function (err, res) { pm.test('Status code is 200', function () { pm.expect(res.code).to.eql(200); }); });
Drag options to blanks, or click blank then click option'
Apm.variables.get('endpoint')
Bpm.environment.get('baseUrl')
Cpm.request.url
D'https://api.example.com/data'
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the URL directly as a string.
Using pm.request.url which is the current request URL, not a variable.
2fill in blank
medium

Complete the code to set a variable for the API key instead of hardcoding it.

Postman
pm.environment.set('apiKey', [1]);
Drag options to blanks, or click blank then click option'
A'12345-ABCDE'
B12345-ABCDE
Cpm.variables.get('apiKey')
Dpm.environment.get('apiKey')
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the API key string.
Trying to get a variable instead of setting it.
3fill in blank
hard

Fix the error in the code to correctly retrieve a variable value.

Postman
const token = [1]('authToken');
Drag options to blanks, or click blank then click option'
Apm.environment.get
Bpm.variables.get
Cpm.environment.set
Dpm.request.get
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.environment.set instead of get.
Using pm.request.get which does not exist.
4fill in blank
hard

Fill both blanks to create a request using variables for URL and method.

Postman
pm.sendRequest({ url: [1], method: [2] }, function (err, res) { pm.test('Response received', () => { pm.expect(res).to.have.property('code'); }); });
Drag options to blanks, or click blank then click option'
Apm.environment.get('requestUrl')
B'POST'
C'GET'
Dpm.variables.get('httpMethod')
Attempts:
3 left
💡 Hint
Common Mistakes
Using method without quotes.
Using pm.variables.get for URL which is usually in environment variables.
5fill in blank
hard

Fill all three blanks to set variables and use them in a request.

Postman
pm.environment.set('userId', [1]);
pm.environment.set('authToken', [2]);
pm.sendRequest({ url: pm.environment.get('baseUrl') + '/user/' + pm.environment.get([3]), method: 'GET' }, (err, res) => { pm.test('User data fetched', () => { pm.expect(res.code).to.eql(200); }); });
Drag options to blanks, or click blank then click option'
A'7890'
B'token_abc123'
C'userId'
D'authToken'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting string values when setting variables.
Using wrong variable name in pm.environment.get.