Postman is a fantabulous tool when trying to play around with APIs. It offers a handy user interface with which to make requests, without the hassle of writing a bunch of code just to test an API's functionality.
Let’s say I want to make a GET request against an API for a Library system to search for books by their name. If I want to do this without using Postman — I would have to write out a whole new program to perform the request, then I would have to specify with more code what I want the response to look like, and finally, I would have to print out the response to the console or provide some other way of actually viewing the response, but doing all this to simply test an API’s functionality is unnecessarily tedious and time-consuming when something like Postman exists.
With Postman, such a test is much more streamlined. All I have to do is plug the parent endpoint into the request URL area, select the GET method on the dropdown box to its left, punch in my API key in the “Headers” section, specify that I want the response in JSON format, and hit send. Then, I get the response data in easy-to-read JSON with a status code of 200, confirming the GET request was successful. It’s that simple! Isn’t that interesting, so why wait? Let’s get started to know more about POSTMAN!
Now that we are using the abbreviation API, what exactly does it stand for?
API stands for Application Programming Interface.
Meaning: It’s software that allows two applications to interact with each other.
Example: When you use an application on your mobile phone, the application connects to the Internet and sends data to a server. The server then retrieves that data, interprets it, performs the necessary actions, and sends it back to your phone. The application then interprets that data and presents you with the information you wanted in a readable way. This is what an API is — all of this happens via API.
Then where does this POSTMAN come into the picture: Like I said before, Postman is a tool used for developing and testing APIs.
Where to download the POSTMAN: https://www.postman.com/downloads/
- POSTMAN offers a list of API call methods we can select from the given dropdown list, set Authorisation, Header, Body information according to the API call to hit our API.
Methods available in Postman:
Header as per the API to be tested:
Body as per the API to be tested:
Then, one can perform the API call by hitting on the Send button.
2. Additional features to know about POSTMAN:
· Environment Variables: We can set the environment variable, from the top-right corner, according to the requirement. One can easily set the environment variable by following the below steps:
-Click on Manage Environment from Settings (icon available at the top right corner).
-Click on the ADD button.
-Write down the Name of the Environment.
- Fill key & value, which can be used as a variable in the collection later.
· In API calls, we mainly use four request methods frequently, which are as below:
-POST Request — For Creating Or Updating data,
-PUT Request — For Updating data,
-GET Request — For Retrieving/Fetching data and
-DELETE Request — For Deleting data.
· Pre-request Script — pre-request scripts are pieces of code that are executed before the request is sent.
Example: In one of my testing purpose I had to reset the counter value defined in the environment variable, below is the snippet for the same:
·Example of Test Result:
· POSTMAN also has a few in-built Test Scripts for our use, it’s available in the Code section of the Tests tab.
Hope now you all might have a glimpse of the POSTMAN tool!
If we have discussed POSTMAN then why not have some insight on his brother Mr. NEWMAN.
Newman gives the capability of running Postman collections through the command line. It basically helps you automate your Postman tests with ease.
Basic Steps of NEWMAN Kickstart:
- Step 1: Install NodeJS
- Step 2: Install Postman’s Newman
- Step3: Create a Collection and Running Tests Scripts
- Step4: Exporting Postman Collection and its associated Environment file if applicable
- Step5: Running the Collection in Newman
Step1: Install NodeJS
Installing NodeJS is pretty straightforward, visit their download page here, download your platform version to install.
Note: Kindly make sure to install the latest higher version.
After installing, go to your Terminal and enter the command below to check if everything is fine to go.
- node -v
- npm -v
You should see an output similar to the one below:
Step2: Install Postman’s Newman :
Now that NodeJS is set up, we need to install “Newman” and some NodeJS modules that will be useful for our test report generations.
Run the below command:
- npm install newman request rimraf newman-reporter-html newman-reporter-htmlextra — save — force
After installation you will see similar output:
Step3: Create a Collection and Running Tests Scripts
In Postman select “New” >> “Collection”. Give a name to the collection. I’ll be using a sample collection in my local which has Test Scripts designed already just for the purpose of the explanation.
Sample Collection with Test Scripts:
Step4: Exporting Postman Collection and its associated Environment file if applicable
Under the ‘View more actions’ option of the collection, select ‘Export’.
Save the Collection to your local directory. The collection should be saved as a .postman_collection JSON file.
Note: To export the environment variables, Go to the ‘Manage Environment’ section from the top right corner and click on Download, environment file will be downloaded s .postman_environment JSON file
Step5: Running the Collection in Newman
Open the terminal and navigate to where the Postman Collection and associated environment json file is saved. To execute the tests run the below command:
newman run Jenkins-Testing.postman_collection.json -e Reltio-MDM-UCI.postman_environment.json — export-environment Reltio-MDM-UCI.postman_environment.json
A similar output will be prompted:
Collection executed successfully through the command line.
Hope the article was useful! Happy Learning! 😊 Happy Testing!
Jency Stella - Senior QA Engineer - Billennium | LinkedIn
8+ years of IT experience, by serving as a channel between the project development team and the clients in analysing…