SDET Unicorns

Introduction to Postman Scripts

Intro to Postman Scripts

Table of Content

In this post, we will do a quick introduction to Postman Scripts. Learning scripting will give you the power to automate your API collections, so it’s really important you understand how Scripting works if you want to do API automation using Postman.

What are Postman Scripts?

Postman Scripting allows you to add dynamic behavior to requests and collections by executing JavaScript code. Essentially, what you are doing is using JavaScript code to manipulate your API requests.

There are 2 types of scripting you can do with Postman –

  • Pre-requests scripts
  • Test scripts

Pre-request Scripts – manipulate the data of the request before Postman sends the request

Test Scripts – validate the response of the request by writing tests (gets executed after Postman receives the response)

What can you do with the Scripts?

Postman Scripts allow you to change the behavior of the requests, let’s understand what that means. Using Scripts you can do some of the following:

  • Set or Get the variable values / parameters / headers / body data etc… in the request directly
  • Debugging (log output to the console)

Let’s take a look at an example –

image 3

Let’s assume you are creating a user using the POST request and then you need to fetch the id of that user in your GET request. Instead of manually copy/pasting the id, you can take advantage of scripts to do that for you.

First, you can set a variable called ‘id’ in the Tests script of the POST request. Then, get the variable in the Pre-request script of the GET request and set it in the parameter.

This allows us to automate this flow using Postman collection without having to worry about relying on existing data.

Check out the video below to learn more about Postman Scripts –


To learn about API Test Automation using JavaScript, check out my free tutorial series here –

JavaScript API Test Automation Tutorial Series


I hope this post helped you out, let me know if you have any questions in the comments below!

Happy testing! 

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

7 Principles of Software Testing

7 Principles of Software Testing with Examples

Software testing plays a crucial role in the software development life cycle as it helps ensure the quality, reliability, and performance of the final product. Software testing is not just about finding defects; it also provides valuable insights into the overall quality of the software. By conducting effective software testing, it shows how well the application behaves in different scenarios and whether it meets user expectations.

Read More »
Differences Between CI/CD and DevOps

Key Differences Between CI/CD and DevOps

Software development is far from a simple journey that involves merely executing code and launching applications. It often presents challenges, as it’s rare to get everything right from the start. Each time you implement new or frequent code changes, you inadvertently introduce potential issues that can be time-consuming to resolve. This complexity necessitates a structured approach to ensure smooth production.

Read More »