Your browser does not support JavaScript!

Blog

Test automation of APIs using Postman
Test automation of APIs using Postman
Automated Website Testing Services
June 27, 2017

API is Application Programming Interface. It is used to establish communication and data exchange between two software systems. A software system implementing an API consists of various functions and sub-routines which can be executed by another software system. API testing is totally different from GUI testing. It basically concentrates on the business logic layer of the software architecture. In API Testing, you use software to send calls to the API, get output, and note down the system's response.

API Architecture: API calls collection includes mainly two things:

1. HTTP headers: HTTP headers are always dependent on your application.

i) Authorization: A token included with requests to identify the requester. This header has to be included in all requests other than the login request.

ii) Content-Type: A standard MIME type describes the format of object data. Content type in most of the requests and responses will be application/json.

2. HTTP Request: There are mainly four types of requests.

i) POST– Used to Create or Update data

ii) PUT- Used to Update data

iii) GET- Used to Retrieve data

iv) DELETE– Used to Delete data

What is Postman?

Postman is used to fire requests to an API. It is available as add-in on Chrome and also available for Mac application.  It is very fast in response and also light weight which puts no impact on browser performance. Tests can be created with verifications for certain conditions on the response. With Postman, you can create different kinds of HTTP requests such as GET, POST, PUT, PATCH and DELETE. It also provides supports for adding headers in the requests. It’s a very convenient API tool with very useful features.

How to perform Automation Testing of APIs using Postman?

Following criteria detailing the process, to perform automation software testing of APIs by using Postman:

* First, install ‘POSTMAN’ add on in Google Chrome.

* Open Postman.

* Click on ‘Create New Collection’ button, fill details and Click ‘Create’ button.

* Now go to newly created Collection and Create New Folder by selecting ‘Add Folder’ option of side menu bar.

* Now Click ‘+’ Button for opening new Tab.

* Now Fill URL, headers, Select Method (Get/POST/PATCH etc.), Body etc. and click ‘Send’. It will show the result in a response. It should return desired results. If there is a problem Please recheck every prerequisites and requirement.

* You can add desired assertions in a particular request in tests tab like:

           tests[“Check: Status code is 201”] = responseCode.code === 201;

* Now ‘Save as’ request by filling its Name, Folder Name, Description etc. It will show the request under your selected Folder/Collection.

* Now Click on Setting Environment Button (Setting Icon on Top right corner under Heart Icon) and select ‘Manage Environments’.

* Click on ‘Add’ Button, Enter Name for environments, Enter Keys and Values. Keys(Name of the variable like URL), Value(Value of Variable like: http://bugraptors.com/). Click ‘Add’. It will create environments.

* Now select newly created environments from DDL (Top right corner with setting Icon).

* Now use the variable as a requirement. Syntax to use is {{Key of variable}}.Like: {{URL}}. It will show variables in a list and you can select from there too. If the variable is accessible it will automatically convert it into orange color either it will reflect in Red color.

* Do the same process for all your APIs.

* Now you can run the whole collection or single folder by Clicking on ‘Runner’ (Top Left corner Button) or Click run from the submenu of the desired collection. It will open Runner Window. Select Collection/Folder, Select required environments, Fill iteration count (If you want to run it multiple times), Fill Delay, Choose Data File if required, and click ‘Start Test’. It will Give you result of every request.

* You can fetch Data from the response of a particular request and store that in variables. The syntax of it is like:

           var jsonData = JSON.parse(responseBody);

           postman.setEnvironmentVariable(“variable_key”, “variable_value”);

* For ‘report’ you have to install ‘Newman’ on your PC. It is command line tool that can generate the report by running POSTMAN collections.

* Now export Postman Collection by selecting Export from the left menu bar of the desired collection.

* Also, export the required environments on manage environments window from download icon button.

Author: HarmanJeet Kaur

Alternative Text

Harman is an Automation Test Engineer at BugRaptors. She has expertise in Web & Mobile automation testing using Selenium WebDriver and Appium Tool. Professional in writing automating test scripts ,Data Driven Implementation , Keyword frameworks, Debugging, Executing and find issues in scripts.

Leave a Reply

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