API Testing Postman
API Testing Postman
1tier architecture:
2 tier architecture:
Client in separate machiene and database in another
3 tier architecture:
Ex:
Here make my trip is connected with different airlines APIs. Make my trip doesn’t have APIs
And you logging in some sites with Gmail account or face book account.
SOAP is not using now a days. very few companies are using. SOAP supports only xml format for
communication.
APIs does not need internet to run. Once it is in production then it is web service.it needs internet.
Here payload is the data. Request payload means what we request and response payload means what it
returns.
Development team send only end point not the complete URL
Some people called it a URL and some people call the total link as URI.
https://reqres.in/ to check requests below, response will come in the json format.
Here you can get the data using browser also by combining host and endpoint. But this is only for get
request. We can not use browser for other requests
For post request we send data to store using request payload and we get some response using response
Payload.
If we send some request we get some response data to verify status code, cookies,headers etc.
Session2:
Supports desktop and web version . we can use tool of both versions.
Create a workspace
Click on new->select workspace
Click on create.
If you don’t have existing workspace , new button will not display. Click on workspace->give name and
click on create workspace.
If you want to delete workspace, click on workspace and right side select settings. Below we get delete
workspace.
Give the workspace name to delete and click on delete button.
Rename:
Click on workspace in right panel. It will allow to rename
Collection:
Contains no of folder and HTTP requests. Under collection we can create new collection, rename and
delete. We can run the collection. We can create any no of collections under workspace. Without
collection we cannot create folder and http requests.
Click on create collection or click on files from 3 dots on left upper corner or click on + icon
Click on new collection and rename it,if you want. Or click on left panel collection name and 3 dots will
appear and take necessary action.
You can duplicate and export import etc we can take actions.
As an input we pass the request and we get the response. we do validations on response.
Requests:
GET
POST
PUT
DELETE
We generally don’t use patch request. We update complete data using put.
Domain or host
Path parameters
Query parameters.
Sometimes you don’t have query parameters. Based on how client framed the APIs. How they stored in
the servers
Click on +icon to create new request or click on 3 dots next to collection. Or click on add request under
collection.
We get the below page.
GET request:
Headers:
Test results will come when we give validation messages.
Right side we get status code, time taken to execute and returned data size.
POST request
When we do POST Request we need to give request payload. For example we are providing json data we have to
click on body-> select Raw-> in the end of the live we get different formats. Select Json from there. And paste the
request body under that box. Developer will give the document which you need to select. Based on the API
requirement we need to provide the data.
URL:https://reqres.in/api/users
Example Request payload
{
"name": "morpheus",
"job": "leader"
}
Id is created to sent data. Data is stored and id created. Next time if you can call the data using id.
If you want to save request click on save button upper right corner and give a name and save the
request under required collection.
PUT request:
We can modify the existing data by sending request payload. Using id we have to call the data. Use it in
URL.
We need to give all the data. From multiple table data, single value update sometimes not allows. Hence
we have to give all data.
DELETE Request:
Select Delete request and send the url and Id and click on send
Status codes:
Session 3:
Download nodejs from nodejs site. No need of installation. Go to the download path and check version
from cmd. Nodejs and npm will come together.
Node - -version
Npn - - version
It is installed.
We are doing installation to check our own demo apis for practice. If other apis are already installed by
organization, we don’t need it.
"name":"arun",
"gender":"Male",
"physics":"88",
"maths":"87",
"english":"78"
},
"name":"rajesh",
"gender":"Male",
"physics":"100",
"maths":"88",
"english":"79"
Now cmd you need to give the path of json file. I have place it where json server is there. And execute
the below command.
json-server students.json
C:\Users\xd5713\node-v20.13.1-win-x64>json-server students.json
You will see below. in demo it showed 1st screenshot. for me 2nd screenshot
Ctrl+C to exit from server
Index is the index for data. We gave 2 records. If you give only index it will show below.
If you use end points it will show the selected data 0 or 1 for 2 records.
http://localhost:3000/0 will show 1st record.
You can use same url in post man tool it will work.
When you close the collection from postman tool. It will stop the server running and shows operations
performed in postman.
When ever we are communicating between client and server, the data will be communicated through
JSON/xml format.
Json data is light weight, and encryption and decryption are possible for security. Return the data in json
format only.
Xml used for SOAP type services and JSOn used for REST services.
What is JSON:
JSON is derived from the JS
Key:Value
Key always included in double quotations.
“phone” : [
1234,
2345
Only string type value should have quotations. Boolean should nt have quotations.
“phone” : null.
The below we call as object data. Because it contains multiple data types.
To insert multiple records:
1.Create an name
Student
2.Add Array
Student:[ ]
Student:[
“name”: “suresh”,
“Id”:20
“Student“ :[
“name”: “suresh”,
“Id”:20
},
“name”: “rajesh”,
“Id”:21
If you want to extract the 1st student name. id etc. we need to write path.
Ex: Students[0].name.
It is difficult write like this. Hence we use 2 tools.
JSON path.
Go to JSON path finder site and place students JSON data in left panel.
Right side it give the data. And when you click on each data. It will generate a path in path field.
X is root path. We can ignore it.
Extract the data. Compare the data with that one with expected data and validate the json response.
Paste the json data in left panel and json path from 1st site and paste it in JSON Path field.
Validating headers:
Content type is in the json format or not? We need to check content type in the headers.
Results
Verify the cookies:
Verify the result in result tab. In the function, if one statement is failed, entire result will be failed.
Validating JSON fields in response:
Verifying values.
Paste the response body in the site and it will give the json schema.
"name": "arun",
"gender": "Male",
"physics": 88,
"maths": 87,
"english": 78
}
According to that schema the result should be there in postman.
We need to store this schema in a variable. And response data we need to store in a variable. We need
to use the below assertion.
You should copy this schema into Test tab for verification and give the below assertion.
Here tv4 is Tiny Validator4 library.
You can select all the requests as collection . right click on collection->select run collection.after clicking
run collection it will show below
1.collection level
2.Folder level
3.Request level.
Sequence of execution
NOTE: Here scripts are displaying as Pre –request and Test tab is displaying as post-response under
scripts TAB.
We define pre-request scripts and post request scripts in collection, folder, request levels.
The above is like println in java. We write these kind of scripts in levels . those will be executed in above
screenshot order and display in console
Variables:
Where? When and why?
To create global variables we need to click environment icon on top right side.
{{glb_URL}}/0
When you type {{ in url tab it will display variables.select from that.
Or after selecting collection you can directly click on variables in the right pane.
Click on icon next to environment variable and click on add button in environment block.
While doing testing select environment and give variable belongs to that environment.
Local variable:
We have to create it in pre-request scripts only. It will execute while running the script.
Showing the creation of variable and using it in the url in the below screen. It is only for this request.
You can create global variable in prerequest scripts. Use below sysntax
Below is usage
You can create environment variables in pre-request scripts like below. Select environment from
environment field and give below script
If you want to remove the variables after execution you have to write unset script
Till now we have used the variables in URL. Now I want to get it into tests.
Chaining:
One response will be the request of another API. This is called chaining.
We have to store the response in one variable. We have to use that in another API.
Chaining process
Click on get your access token link. And sign up.It will return the token.
Now we need to check the response data with request data which is given in environment variables.
Document:
Session 7:
Books API
Use below url for post order and give the body.give the authentication token in collection level.If there is
not much requests which uses token, then for those we have to change as no auth instead of inherit
authorization option.
Get all orders
Update order:
Delete order :
Goto authorization in that request and select type bearer token and give the variable in {{}} in token field
Here for data driver testing we use json and csv formats.Here we are going to create below 3 requests
Create a csv file.Select the data from the above book api.check availability true.
If you want to code directly with out writing for click arrow mark. It will display list of snippets .select
that and it will display script automatically.
Pm.json.response will get the response body. And place environment variable order id in the URL.
Select run collection and enter no of iterations and select the csv file path in the data filed select file.
After uploading file. Preview button will show. Click on that , it will show you uploaded data.
We need java for this.Here we need to use file-upload-RestAPI. Jar file. Place jar file any where in
system.
In the body we need to select form-data and enter key as “file” select from drop down and value select
the file. And save. And click on send.
This will upload file and gives URL to download and file details
http://localhost:8080/uploadMultipleFiles
If you select the text Option. You have specify the path manually.
Authentication(authorization):
Uid:postman
Pwd:password
For digest authentication disable retrying checkbox should be unchecked.don’t need to think
about advanced configuration. When it is required only we have to edit it.
Session 9:
PETSTORE API
URL:https://petstore.swagger.io/
Create user:
Use the body in your request . it will give xml response.
Click on try it out. Wt will generate the response in xml format. It generates curl also.
Copy curl response and create a new collection in PM-> select collection and click on import->Go
to raw text and paste curl
Click on continue->import.
url is
Curl will directly brings the body to the request.