Complete the code to log the response status code in Postman test script.
pm.test("Status code is 200", function () { pm.expect(pm.response.[1]).to.eql(200); });
The pm.response.code property holds the HTTP status code of the response. Using it in the test checks if the status is 200.
Complete the code to check if the response body contains the string 'success'.
pm.test("Body contains success", function () { pm.expect(pm.response.text().[1]("success")).to.be.true; });
The includes method returns true if the string contains the given substring.
Fix the error in the code to correctly parse JSON response and check a property.
pm.test("Check user id", function () { let jsonData = pm.response.[1](); pm.expect(jsonData.userId).to.eql(1); });
The pm.response.json() method parses the response body as JSON and returns an object.
Fill both blanks to check if the response header 'Content-Type' is 'application/json'.
pm.test("Content-Type is JSON", function () { pm.expect(pm.response.[1].get([2])).to.eql('application/json'); });
The pm.response.headers.get() method retrieves the value of a header by name. Header names are case-insensitive but usually written as 'Content-Type'.
Fill all three blanks to create a test that checks if the response time is less than 200ms.
pm.test("Response time is fast", function () { pm.expect(pm.response.[1]).to.be.[2]([3]); });
The pm.response.responseTime gives the response time in milliseconds. The assertion to.be.below(200) checks if it is less than 200ms.