Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the mock server URL in Postman.
Postman
pm.environment.set('baseUrl', '[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using localhost or non-HTTPS URLs for the mock server.
Using the real API URL instead of the mock server URL.
✗ Incorrect
The mock server URL must be a valid HTTPS URL provided by Postman mock server, like 'https://mockserver.example.com'.
2fill in blank
mediumComplete the code to send a GET request to the mock server URL stored in environment variable.
Postman
pm.sendRequest(pm.environment.get('[1]') + '/users', function (err, res) { pm.test('Status is 200', function () { pm.expect(res).to.have.property('statusCode', 200); }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist in environment variables.
Forgetting to add the endpoint path after the base URL.
✗ Incorrect
The environment variable 'baseUrl' holds the mock server URL, so we get it with pm.environment.get('baseUrl').
3fill in blank
hardFix the error in the test script to correctly check the response status code from the mock server.
Postman
pm.test('Response status is 200', function () { pm.expect(res.[1]).to.eql(200); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'res.status' or 'res.code' which are undefined in Postman response object.
Using snake_case instead of camelCase for property names.
✗ Incorrect
In Postman test scripts, the response status code is accessed via 'res.statusCode'.
4fill in blank
hardFill both blanks to create a test that checks the response body has a 'message' property equal to 'Success'.
Postman
pm.test('Body has success message', function () { pm.expect(res.[1]).to.have.property('[2]', 'Success'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.body instead of res.json() to access JSON properties.
Checking for wrong property names or values.
✗ Incorrect
Use res.json() to parse the response body as JSON, then check it has property 'message' with value 'Success'.
5fill in blank
hardFill all three blanks to write a test that verifies the response header 'Content-Type' includes 'application/json'.
Postman
pm.test('Content-Type is JSON', function () { pm.expect(res.[1].get('[2]')).to.include('[3]'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.headers.get instead of res.header.get.
Checking for wrong header names or exact match instead of includes.
✗ Incorrect
Use res.header.get('Content-Type') to get the header value, then check it includes 'application/json'.