Complete the code to send a GET request to an API endpoint using Postman scripting.
pm.sendRequest('[1]', function (err, res) { pm.test('Status code is 200', function () { pm.expect(res.code).to.eql(200); }); });
The URL string is required to send a GET request to the API endpoint. Other options are either code snippets for assertions or logging, not URLs.
Complete the code to check if the API response body contains the key 'success' set to true.
pm.test('Response has success true', function () { const jsonData = pm.response.json(); pm.expect(jsonData.[1]).to.eql(true); });
The key 'success' is expected in the response JSON to be true. Other keys are common but not the target here.
Fix the error in the assertion to correctly check the response status code is 404.
pm.test('Status code is 404', function () { pm.expect(pm.response.code).[1](404); });
The correct Chai assertion method is 'to.eql' to check equality. Other options are invalid or incorrect syntax.
Fill both blanks to create a test that checks the response time is less than 200 milliseconds.
pm.test('Response time is fast', function () { pm.expect(pm.response.[1]).to.be.[2](200); });
'pm.response.responseTime' gives the response time in ms, and 'to.be.below' checks if it is less than the given value.
Fill all three blanks to write a test that verifies the response JSON has a 'data' array with length greater than 0.
pm.test('Data array is not empty', function () { const jsonData = pm.response.json(); pm.expect(jsonData.[1]).to.be.an('array').that.[2].length.[3](0); });
'data' is the key for the array, 'has' is used to assert property existence, and 'above' checks length greater than 0.