Postman Notes
Postman Notes
Postman Notes
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
POSTMAN GUIDE
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
API = When we have an API in our local environment than its called API
Web Service = When we move API from local to production environment then the API is called Web
service. Web service is an API which is wrap in HTTP
Note: All services are API but all APIs are not web services
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
SOAP API
SOAP is a very old and complex technology and its only supports XML for communication. It supports
only post requests only.
RESTful API
RESTful is the latest technology and its supports multiple ways to communicate like XML, Text,
HTML, and JSON, and it supports multiple operations like Post, put, get, set, etc. Most of companies
are using RESTful API nowadays as it’s the latest and has more features
All the tasks will be saved in the workspace which will be created in Gmail or logged in the account
COLLECTION
STRUCTURE OF URL
https://reqres.in/api/users?page=2
https://reqres.in = Domain
/api/users = Path Parameters
page=2 = Query Parameters
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Once we hit it, we can see the response below in the body section. We can see the response in
multiple ways XML, HTML, Text, JSON, etc. There are also multiple representations of response as
well as Pretty, Raw, Preview & Visualize
Once we are done with the then we can save the request into the desired collection
From the browser we can only send GET request. For all other request we need to use postman
After getting the response from the API if the status code is 200 , 201 then its mean our request was
successful and all other codes mean there is some problem
Authorization = Login Authorization , Token and some API are completely restricted so in that case
we need to pass Authorization
Pre-Request Script = Any script that we want to execute before sending the request
Test = Most important , we add validation her. All other script will also part of this tab
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Sometimes we need to find the JSON path of the node in order to hit it.
We can find json path by one of online website https://jsonpathfinder.com/
Below code is demo of that
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
• Click on … of Collection
• Select “Run Collection”
• Do Some Configuration & Its Done
POST REQUEST
Request payload = We need to send data with our request and its optional
Response payload = We will always get it against any response
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
NOTE: we must send the data in the body in a specific format which we will select from drop-down
POST should be selected from the request type. If we select JSON for sending data then our data
must follow the JSON format. This is very sensitive and we must follow this rule
We cannot validate token upon login as its always new and generated dynamically all the time but
we can validate if the token is generated or not.
POST REQUEST FOR CREATING NEW RECORD
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
LOGIN VALIDATION
PUT REQUEST
Old Data
{
“name” : “Junaid”
“age” : “17”
}
New Data Which is need send in the request body for updating
{
“name” : “Junaid”
“age” : “18”
}
http://dummy.restapiexample.com/api/v1/update/2
DELETE REQUEST
http://dummy.restapiexample.com/api/v1/delete/2
Data-driven testing means we can run the same request with multiple sets of data
We can validate header by using below mentioned code
Here “Response” is element of header and we need to mentioned the desired element of header
here. Keep in mind that we cannot validate the values of all the headers as some elements get value
NOTE: In Postman we can prepare test data in JSON or CSV format only
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Body Request
{
"name" : "{{name}}" ,
"salary" : "{{salary}}" ,
"age" :"{{age}}"
}
STEPS
1. Prepare the CVS File
2. Add the above mentioned code in body
3. Run the Runner (File > New Runner Window)
4. Runner will get open in new window/sometime as a tab
5. Select the desired workspace if runner get open as new window
6. Select/drag the desired collection if runner get open as tab
7. Select the … and then click on run if runner get open as new window
8. Select the itereation (depend on data)
9. Select Delay = should be mini 10 ms because as a bulk API will take time to respond
10. Select CSV File From PC
11. Hit the Preview – It will only preview if our data is in correct format
12. Hit Run
NOTE: Both JSON & CSV file has exactly same method only file format is different.
In JSON we need to prepare and attach the file in JSON format.
In CSV we need to prepare and attach the file in the CSV
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
POSTMAN VARIABLES
Sometime we need to use the same data for multiple request in multiple API so we can create a
variable to store that data so we don’t need to write the same data again and again. We just need to
send that variable in request
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
e.g base url of all API are almost same we can store that in variable so that if base url get change in
future then we don’t need to update it all APIs. We will just change in variable and it will get change
automatically in all APIs.
Collection Variable
• https://reqres.in/api/users?page=1
Here https://reqres.in/api is going to use for request so we can store it in variable and use that
variable.
1. Click on Collection
2. Select Variable
3. Give Varaible Name & Path
4. Hit Save
Note: We can also create the collection variable by using pre-request script by javascript coding
Postman by default post code snippet to create the variable by using code snippet and the variable
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
which will be create by using pre-requset script method, will be create dynamically on runtime
Environments/Global Variable
Environments Variable – This variable varies from environment to environment. E.g there could be a
chance the there will be different environment like QA , UAT , Staging etc and these environment
will have different url etc. So we can create variable inside this environment and it will be effective
with in that environment.
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
WORKFLOW
Let suppose that there are 5 request in one collection. By default they will run in sequence but if we
want to control their flow and run them in our desired order then we need to small command in
test tab.
Whatever API url we will give in this statement will get executed and we can our own order in this
way
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
API Chaining request mean, using the output of one request as an input of other request. For
example ther are multiple users and we want to update the the user 2 with the name of user 3.
• Execute the PUT request and in first name send {{variable name}} as parameter
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
If we click on ... which are available in front of collection and click on documentation then it
will give all basic code snippet that we can use while creating scripts
TYPE OF SCRIPTS
There are 2 types of scripts
Pre-request - Which run before the request
Test - Whic run after the request
We can have multiple folder inside collection and multiple request inside each folder
COLLECTION
FOLDER
REQUEST LIST
So, we can write scripts at collection level, folder level and request level. Its all depend on
our need and requirement
Once all done then we can run the whole collection using runner and check the response in
Console. We can open console by Alt + Ctrl + C
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
We can verify all the data from response. There are some basic snippet which are pre available in
postman and we can also create our own assertion as per the need. Below mention code will verify
some element from JSON response and we can use same code to validate any JSON element
//Multiple Assertion
//This Assertion will verify the response ID is equal to expected or it
//Similar way we can verify every element like Name, age , email , course , etc
In above code we are verifying multiple element in one shot. If anyone of them get fail then it will
show that whole assertion got failed
Note: we need to user JSON path finder in order to use that in code. In above code
‘data.first_name[1]’ is JSON path of first name which we have found by using below webisite:
https://jsonpathfinder.com/
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Sometimes JSON response don’t get parse successfully. We can still validate data by handling the
response is text format. Use the below code in such a situation
Suppose there are different status code and we are expecting anyone of them then we can validate
the list and test will get pass if anyone of expected code get received
We can validate the specific header is present or not by using below code.
//Testing Headers
pm.test("Content-Type Header Present Or Not", () => {
pm.response.to.have.header("Content-type");
pm.response.to.have.header("Server");
})
We can also the validate the value of header if its as expected or not
pm.expect(pm.response.headers.get("Content-
type")).to.be.eql("application/json; charset=utf-8");
})
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Note: We can validate the header and its value in once test as well. Above mentioned example are
for making clear understanding. We can use below mentioned code to perform both validation.
})
By using above mentioned code we can easily validate all the header and its values
pm.expect(pm.cookies.has(" Cookie")).to.be.true;
})
})
We can also validate cookie and its value in one test. Above mentioned code is written seperatly just
for the clear understanding
pm.expect(pm.response.responseTime).to.be.below(120);
})
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Export Collections
Import Collections
1. Click on Import
2. Upload file and hit import
3. It will import collection
4. We can import collection multiple way
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
We can create the small document of our collection which show which request we have sent and
all other information. It will be public URL and anyone can see it as a report
Click on Publish
Hit publish
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed
Follow Junaid Aziz For Complete Career Counselling & Interview Preparation of SQA
Follow Junaid Aziz For Free Resume Review To Make It ATS & SEO Friendly To Get Noticed