Write Postman Test Script for Validate Response

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

To the above exercises, write a test script to verify that the status code is 200, response time should be less than 2000ms and the response body must contains the string “title” as a key.

Solution

Open the specific request and go to Tests tab where you want to add test scripts.

To validate the response code

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

To validate the response time

pm.test("Response time is less than 2000ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(2000);
});

To validate the response body string

pm.test("Respnse Body matches string", function () {
    pm.expect(pm.response.text()).to.include("title");
});
Postman Practice Exercises - QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.