Automated API testing with Postman

API

Hello everyone!! If your company maintains API for their products and you are a person who is responsible for testing the API endpoints then this blog is for you. This blog will be explaining how to get started with API testing using Postman. First we need to know a bit about API and Postman.

What is API?

API stands for Application Programming Interface.Its a set of blocks of code which are connected with different protocols to communicate with each other to make a connection between the Database and the GUI which makes a successful software.

There will be several endpoints which will access data from the database. The endpoints should be secured to make them fetch the right data for the right user. This is a tricky part for API. If any endpoint returns wrong data to the end users and the wrong data is something that end should never get access to, that can be a mess! So its really important to make it work correctly and tested properly.

Get started with API testing with Postman

To get started with API testing first you will need a tool. Postman is a good tool for this job. Download postman from here and install it to your machine. After the installation you will be asked to sign in. Use your google account or just register to postman. And you are ready to start the testing. 

This is a view from postman. 

1 –> Select the request type
2 –> Insert the request URL of your API endpoint
3 –> Its optional. If your API endpoint have parameters, add them here

Once you are done with these 3 points add value to header and body. Then hit Send button and the response will be seen here in the Response box. Check out the desired responses. If wrong/error response then the endpoint needs to be fixed.

This is how you work manually. To save your time its important to make your tests automated. For this its important to have all the endpoints available and documented properly. Make a Collection with the endpoints and sort them sequentially.

Now how to sort endpoints to a collection? Lets consider a login scenario. If you try to login to your mail, Postman generates a token with your username and password. With the token you can check your mails. there will be one endpoint to generate token with your login information and the other endpoint will use the token to fetch your mails to you. So the login endpoint must be the first one and then the endpoint which fetches the mails will be sorted next to it.

How do you make it automated? Here you will need to set up Environment for your tests.

Lets say you have generated a token with your login information:

postman token

 

And you will be using this token to check your mails with another endpoint. So what you do, you copy your token paste to the header of the next endpoint. This is the manual style. To make it automated you have to create an environment variable through Test Scripts:

save token to environment

 

Then the token gets saved in your environment. Now each time you need the token to check your mails and visit your profile you just call the variable with your endpoint and you get the response.

postman environment

Once you complete setting up your environment save it for the tests. Now go to the collection runner. There select a collection and corresponding environment. Click on Run Collection and the responses will be shown in the box at right side:

collection runner

Once its done the result will be saved automatically and the result can be imported for analysis. if any endpoint fails to fetch the correct information or gives any error response that result is marked as red and the successful one marked as green.

Posted in API Testing, Test Automation, Uncategorized and tagged , , , , .

Leave a Reply

Your email address will not be published. Required fields are marked *