Complete the code to set the request method to GET in Postman test script.
pm.request.method = '[1]';
The GET method is used to retrieve data from an API. Setting pm.request.method to 'GET' ensures the request fetches data.
Complete the code to check if the response status code is 200 in a Postman test script.
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
Status code 200 means the request was successful. This test checks if the API responded correctly.
Fix the error in the Postman test script to correctly check if the response body contains the key 'userId'.
pm.test('Response has userId', function () { pm.expect(pm.response.json()).to.have.[1]('userId'); });
The property assertion checks if the JSON response has a specific key like 'userId'.
Fill both blanks to create a test that checks if the response time is less than 500 milliseconds.
pm.test('Response time is fast', function () { pm.expect(pm.response.[1]).to.be.[2](500); });
pm.response.responseTime gives the response time in ms. The below assertion checks if it is less than the given value.
Fill both blanks to write a test that verifies the JSON response has a 'name' key with value 'John'.
pm.test('Name is John', function () { pm.expect(pm.response.json().[1]).to.[2]('John'); });
This test accesses the 'name' key in the JSON response and asserts it is equal to 'John'.