Tests Tab in
POSTMAN
By,
Saajan Varghese
Agenda:
• What is Test in PostMan
• What Happened to Tests Tab in PostMan
• What is Pre-request and Post-response
• Scripts Tab in PostMan
• CRUD Operation to Test an API on a local machine
• Summary
prepared by Saajan Varghese
What is Test in PostMan Tool ?
• Test in PostMan is used to test the API’s Request Header,
Response Header, Request Body and Response Body.
• Test is used to do Manual Testing in PostMan.
• Tests confirm that your API is working as expected, that
integrations between services function reliably, and that any
changes haven't broken existing functionality.
prepared by Saajan Varghese
Early 2024, had Tests Tab
From 2024, replaced Tests Tab with Scripts
prepared by Saajan Varghese
What Happened?
prepared by Saajan Varghese
Here, is the Reason
Source: Postman Community
prepared by Saajan Varghese
What is Pre-Request and Post Response ?
• Pre-request: A Pre-request Script is executed before the API
request is sent. It’s commonly used for:
• Setting variables dynamically.
• Generating authentication tokens.
• Encrypting or signing requests.
• Adding timestamps or unique IDs.
• Post response: A Test Script is executed after the response is
received. It’s used for:
• Validating response status, body, headers, etc.
• Extracting data from the response and setting it as a variable.
• Writing custom logic for assertions.
prepared by Saajan Varghese
Pre-request Tab under Scripts in
Post-response Tab under Scripts in
prepared by Saajan Varghese
Let’s do CRUD Operation to Test an API on a Local machine.
Step 1: Click here on my Repo:
https://github.com/saajanvarghese/API_testing/tree/main/API_Testin
g_Json_Server_1
Step 2: Download books.json file.
Step 3: Follow README.md to Setup the server on a local machine.
Step 4: Open
Step 5: Create New Collection and name it as
Step 6: Enter URL
prepared by Saajan Varghese
Step 7: Create and type the following in the Body.
Step 8: Open Scripts -> Post Response, type the code to capture “id”
which is dynamically generated by the server.
prepared by Saajan Varghese
Step 9: Click to send the request.
You will get a 201 Created response from the server
Note: Copy the value of “id” to create an Environment Variable and
pass it in the URL
prepared by Saajan Varghese
Step 10: Create and type the following in Scripts -> Post-
response to test 200 if data is present, 404 if data is not present and
Script to verify if the dynamic value is changed or not in this GET
Request.
{{dynamicID}} is an environment variable, will be discussed in
upcoming slides.
prepared by Saajan Varghese
You will get 200 OK from the server as Response.
In Test Results you will get 1 Test FAILED because the data is already
present in the server.
prepared by Saajan Varghese
Steps to Create an Environment Variable in PostMan
1. Click on top-right corner in PostMan.(red sign indicates an
empty variable in the request).
2. Paste the “id” value and hover on the
value and click on “+” and create an Environment
To Add Variables in your collection:
1. click on from the top-right corner of PostMan.
2. -> select {{dynamicId}} ->
(Please make sure -> and -> from Request
URL after completing the steps)
prepared by Saajan Varghese
Step 11: Create and type the following in Scripts -> Post-
response to test 200 if data is present or not.
You will get 200 OK as server-response
Test Results PASSED
prepared by Saajan Varghese
Step 12: Create and type the following Body.
{{updatedTitle}} is a variable.
To add {{updatedTitle}} as an Environment, refer Slide 13 to create a
new Environment Variable.
Give the {{updatedTitle}} value as “Harry Potter and the Prisoner of
Azkaban”
prepared by Saajan Varghese
Step 13: Open Scripts -> Pre-request, type the Script to verify if the
{{dynamicId}} is changed or not in this PUT Request.
Step 14: Open Post-response and
type the script to Test 200,
if updated title from the response
body === {{updatedTitle}}
prepared by Saajan Varghese
You will get 200 OK as server-response
Test Results PASSED
prepared by Saajan Varghese
Step 15: Create and type the following in Scripts -> Pre-
response to test if {dynamicId}} is changed or not in this DELETE
Request.
Step 16: Open Post-response, Type a script to Test 200 HTTP Response
prepared by Saajan Varghese
You will get 200 OK as server-response
Test Results PASSED
prepared by Saajan Varghese
Now, lets check if the Deleted Book is present or not from Slide 11
Run again to verify.
You will get 404 Not Found as the data is not present in the server
database
In Test Results you will get 1 Test FAILED because the data got DELETED
as we passed Delete HTTP Request.
prepared by Saajan Varghese
Summary:
• Test in PostMan is used to test the API’s Request Header, Response
Header, Request Body and Response Body.
• Pre-request: A Pre-request Script is executed before the API request
is sent. It’s commonly used for:
• Post response: A Test Script is executed after the response is
received. It’s used for:
• CRUD Operations: Run an API on local machine using GET, POST,
UPDATE, DELETE from PostMan and Test these Methods under
Scripts Tab using
https://github.com/saajanvarghese/API_testing/tree/main/API_Test
ing_Json_Server_1
prepared by Saajan Varghese
Thanks for Reading
By,
Saajan Varghese