What are Scripts In Postman?


Postman is developed on Node.js that gives dynamic characteristics to Collections and requests. We can create test suites, execute requests having changing parameters, send data in between requests, and so on.

A JavaScript can be associated with a request twice. Once before the actual request has been sent(as a pre-condition script added under the Pre-Request Scripts tab)and after the Response from the request has been received (as a test script added under the Tests tab).

Let us send a GET request along with Pre-Request and Test scripts.

Pre-Request Script −

console.log("Tutorialspoint - Postman")

Tests

console.warn("Warning message in console")
console.log("Logging message in console")
console.info("Info message in console")
console.error("Error message in console")

Add an URL in the address bar and send a GET request. In the below image, the Postman Console Output displays the message from the Pre-Request script printed before the execution of the GET request. Then the GET request got executed, finally the script that has been added as a part of Test scripts got printed.

Execution order for scripts in Collection

  • A Pre-Request script added to a Collection shall execute prior to all the requests in that Collection.

  • A Pre-Request script added to a folder shall execute prior to all the requests in that folder.

  • A Test script added to a Collection shall execute post execution of all the requests in that Collection.

  • A Test script added to a folder shall execute post execution of all the requests in that folder.

Updated on: 25-Jun-2021

459 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements