Postman

POSTMAN is an API client that is used to develop, share, test APIs. It is also used for creating documentation for APIs. Test suites can be quickly designed using Postman, and also it can store test information to be used in other tests. It is integrated with Plugins, such as Jenkins's, which makes it more powerful.

API is an acronym for Application Programming Interface. For example, we want to get data from the webserver. Now the application, we will send the request to the server and get the data back and present it to us in a human-readable format. This is what API does.

The Postman can be either download as software and can be installed into your system or it can be added as a chrome extension. We shall see the downloadable software.

Getting Started with Postman Software

To start using POSTMAN, we shall first download the software and install the software. The following are the steps:

Visit the POSTMAN official page & Creating Free POSTMAN account:

Visit the POSTMAN official page https://www.getpostman.com/

After you visit the above page, you should see a Sign in button in the top right corner.

postman-official-page

Now click the Sign-in button on the website and you will be navigated to the free account creation page.

postman-create-account-option

Create your account after filling the necessary details.

postman-free-account-creation

Now after signing in, you must see the page as below:

postman-workspace

Now, check your email, and you might have received the confirmation email from POSTMAN.

postman-email-confirm

Now after confirming the email, you must see a confirmation page like as below:

postman-email-confirmed

Click on the Head to your profile to get started.

Download the software:

To download the POSTMAN software visit the official page of POSTMAN https://www.getpostman.com/downloads/

postman-download-page

Now, click on the Download button and select the OS in which you want to install the software. I have chosen the 64-bit option. You may choose the 32 bit if you are using a 32 bit OS.

postman-select-os-download

After you select the OS, the software should start downloading, as shown below:

postman-software-downloading

Now, once the download completes, open the file and start installing the software. By default, the software should be inside the downloads folder, if you are using the windows and have not customized your download location on your computer.

postman-application-software

Right-click on the software and choose open to install the software.

postman-software-run

The POSTMAN software gets installed in the background, and it does not inform the user on completion.

Once installed, sign in with the username and the password, which you used at the time of creating the POSTMAN account. Once signed in, you should see the following page:

postman-first-interface

Now, we are ready to use the software.

POSTMAN can also be directly added as a chrome extension, but we shall see this later

Introduction to the Interface of the Software:

Click on the POSTMAN icon on the desktop to get started with the software.

postman-icon

By clicking the New button, you can get all the options.

postman-new

After clicking into the New button, a dialogue box will be displayed as below:

postman-new-button-options

The first tab is the Create New, inside which the following options are there:

  • Request
  • Collection
  • Environment
  • API Documentation
  • Mock Server
  • Monitor

The second Tab is the Templates:

postman-templates

The third tab is the API Network:

postman-api-network

Sections of the Interface:

There are different sections in the interface of the POSTMAN software. Let us see all the sections one by one.

Header Menus

The portion of the interface marked with blue color is the header section, which consists of all the options and all the control buttons for the software.

postman-header

New

The New button is used to open the dialog box, which consists of different shortcuts to templates, collections, documentation, APIs, etc.

postman-new-button

Import

The import button can be used to import collections into the software. There is a facility to drag and drop. The collection files can be either imported from any location or can be dropped into the software interface itself.

postman-import-button

Runner

The Runner button will directly run the collection loaded into the software.

postman-runner-button

Open New

The below diagram shows all the different options which pop out when the Open New button is pressed. The options available inside it are: (Open new)

  • Tab
  • Postman Window
  • Runner Window

postman-open-new-button

History

The History section is situated under the filter search bar. This contains all the request that was sent or made by the POSTMAN software.

postman-history

Collections:

The collection helps us to group related requests and thus making them easier to run. This is the section for the collections. When we import any collections or drag and drop any collection into the software, then all the list of the collections will be visible in this section.

postman-collections

APIs

In this section, all the APIs are listed.

postman-api-section

Request Window:

In the Request window, as shown in the below image, all the details and the attributes of the request made by the POSTMAN software will be displayed.

postman-request-window

Inside the Request Window, we have details such as- Params, Auth, Headers, Body, Pre-req Tests Settings. And also, the URL bar is inside the request window.

Response Window

In the response window, all the elements that are sent back from the server are displayed. In our case, no request is made, so no response has been received.

postman-response-window

Creating the First API Request

In this section, we shall see how to create an API request, run the request, and analyze the response we get from the server.

Below are the steps of creating an API Request:

Create a New Workspace:

To create a new workspace, start the POSTMAN software and click on the My Workspace icon.

postman-workspace-icon

When you click on the My Workspace Button, then you will see a create new option popping out. Click on that, and name a new workspace.

postman-create-new-workspace

The workspace name can be any name. In my case, I have named it with workspace01. And then, click the Create Workspace button at the bottom.

postman-create-new-workspace-name

Click the New button on the top left corner of the POSTMAN homepage interface, and once you click the button, a drop-down menu appears that contains all the shortcuts.

Select the request option from the drop-down list.

postman-select-new-request

Now, as you click on the Request option, you will be prompted to enter a request name.

postman-save-request

We will be using the website, http://reqres.in for testing the API.

Now, as we scroll down the page (http://reqres.in), you will see that several Requests are listed there. We shall select the Single User. So, click the Single User and then copy the URL from the search bar. And copy the request endpoint.

postman-api-request

Now open a new tab in the browser type the main URL along with the Request endpoint. Once you press enter after giving the complete link(http://reqres.in/api/users/2) into the URL bar. You must see the response from the server.

postman-response

After that, add a name to the Request and create a new collection and save the request and the collection as well.

postman-request-and-collection

In my case, the request name is the Get Response, and the collection name is Collection01.

Now, copy the request URL(http://reqres.in/api/users/2) and paste it into the URL bar in the POSTMAN.

postman-paste-url

Once done, now simply click the send button.

postman-send-button

Then, you must see the response as below:

postman-response-from-server

Creating Collection in POSTMAN

POSTMAN Collections are groups of pre-built request that can be organized into folders so that, that can be run independently. Collection can also be shared with other collections. All the APIs requests can be stored and saved inside a collection.

Here, we shall see how to create a collection, create folders inside a collection and how to share a collection. Also, we shall see how to arrange requests inside a group.

To create a collection, open the dialog box by clicking the New button and select Collections.

postman-collection-window

As shown above, select the Collection and the collection window will open. Here, you can create your collection, by merely entering the collection name.

postman-collection-creation

In my case, the name for my Collection is Collection02. In the Collection window, there are different tabs such as the- Description, Authorization, Pre-request Scripts, Tests and Variables.

Now click on the Create Collection Button to generate the collection. It will be an empty collection.

postman-collection-created

Adding folders into the collection

To create folders inside the collection, click on the collection name and a drop-down menu will appear below the collection name. Select the option called- Add Folder as shown below.

postman-collection-add-folders

Once the Add Folder option is selected, you will be navigated to a pop-up window to enter the folder name. In my case, the folder name is folder02. Then click on the create button to create the folder.

Not only one folder but many folders can be created inside a collection.

Running Collection in POSTMAN

To run the collection, we shall take the example of our earlier collection - Collection01, and the API request inside it.

Now, before we start to run the collection, we shall try to add some more requests inside the collection, so that, we can get a more comprehensive view of how a collection is run.

To add more API Request, we shall navigate the website(as we did earlier)- http://reqres.in. And search for a different API Request.

postman-another-request

As you can see, this time we have selected the LIST USERS. And so the URL is copied along with the Request end-point of the Request - /api/users?page=2, as shown in the picture. Now paste the same URL, into the URL bar of a new tab in your browser and check whether you get the response as below:

postman-second-response

Now, as seen above, the response from the server is received successfully. Now, navigate to the NEW button in the POSTMAN again to open the dialog box and select Request. This is to create a new Request.

Now, create a new folder named GET, inside the Collection - Collection01 and drag and drop the two create requests- GET Response and GET_user_list into the build folder. This is done just to arrange things in a proper way.

Now, navigate to the collection tab and select the collection you want to run. For, my case it is- Collection01.

postman-collection-tab

Now, you may open the collection folder to see what are the requests inside it. Then select the right arrow on the right side of the collection name, and you should be able to see the RUN button.

postman-collection-arrow

The RUN button will appear once you hit the arrow on the collection.

postman-run-button

Then the next confirmation window will pop up. Select the Run Collection button, and you are ready to go.

postman-run-collection

Once, you hit the button- Run Collection01, you should be able to see the below window:

postman-collection-run-output

As you can see the output above, the Collection Runner has popped up in a new window, and all the results are inside the window.

The Result window consists of the Request Name, the link visited, the status of the response (which is 200 here, means OK), the time required to get the response (in mili-seconds). And the size of the response data.

Creating and using variables in POSTMAN

Variables are used to store a part of the URL in POSTMAN. Using this concept of storing a part of the URL in a variable and using it in multiple places which can save the time of typing a lengthy URL. This technique can also be used to identify a URL very easily.

In this section, we shall create a variable, use variable, and refer a variable. Variables are used when a part of different URLs is a common text.

For example, two requests which are inside the collection- Collection01 have the first website link in common; just the request end-points are different. Therefore, the first part can be stored in a variable so that, the variable can be used when the website URL is required.

To open the variable section and click the three dots beside the collection name, and then a drop-down list will appear. Select edit from the list.

postman-edit-variables

After you select edit, you should see as below:

postman-variables

Now, click on the variable tab and you will be asked to enter the key, which is the variable name(anything you want). Now, copy the first part of the URL which is common to both of the requests.

In our case, one URL is: https://reqres.in/api/users/2

And another URL is: https://reqres.in/api/users?/page=2

Therefore, you can see that the URL part https://reqres.in is common to both the above URLs. Therefore, we shall try to store this part of the URL in a variable, and try substituting it inside the POSTMAN software and see whether it works.

To do so, click on the Variables and then name the key(the variable) and then edit the part of the URL into the URL bar. And then select the Update button.

postman-variable-edit

After you have named and updated your variable, go to the URL bar and replace the part of the URL with the variable you declared.

In our case, the variable is the url and so the syntax contains URL between a pair of braces {{ }}

postman-variable-replacement

After successful replacement of the variable, you are ready to go. Now, send the request again and it should work the same way it worked earlier.

postman-send-button-check

Check the output now:

postman-variable-replacement-working

Set And GetVariables using Scripts:

In this section, we shall see how to Set and Get variables using scripts. To write test scripts, go to the Tests tab.

postman-test-tab

Now, inside the Tests tab, there is a console editor, you can start writing your script here. console.log() is used for printing a specific value.

console.log("Hello World!");
let urlVar=pm.variables.get("url");
console.log("The value for the URL variable is: "+urlVar);

After you click the send button, go to console window (by clicking the view button) and you can see the output. The variable which we named earlier for the URL, can be retrieved using the script.

postman-variable-in-console

Now, to set variables use pm.variables.set("Variable-name","Variable-value"), And type the following code inside the > and the other is the team. We shall see only the personal, as the team workspace is available only in the pro version of the POSTMAN software.

postman-workspace-types

To create a new workspace, simply click on the Create New option, as shown in the above image. Enter a name for the workspace and select the type as personal.

postman-personal-workspace

postman-new-workspace

Now, once you click on the Create Workspace button, your workspace is created and as long as you are inside the workspace, all the API requests or API collections you write are under the same workspace.

Now, you can create a different workspace as per requirements. And also, collection from one workspace can be added into different workspaces.

To, add a collection in your current workspace from a different workspace :

Navigate to any of the workspaces you want and then, click on the Browse option which is on the bottom-right corner of the POSTMAN screen.

postman-browse-option

After clicking on the Browse option, you will be able to see all the collections of the current workspace.

Now, click on the option Add to Workspace,

postman-add-to-workspace

After you click into the Add to Workspace, you should be able to see a drop-down button called Source Workshop. And select, any workspace you want. I have selected, My Workspace.

postman-workspace-list

Now, you select a collection, you must see this below the window where you can select collections. You can select some collections or all collections.

postman-collection-addition-list

After you have selected the collections, click on the Add to Workspace button.

postman-add-to-workspace-button

Once, you click into this button, all the collections you selected will be added to your current workspace.

Deleting a collection from workspace

To delete a collection, simply click on the triple-dot present on the right side of the collection name.

postman-delete-collection

Sharing a collection in POSTMAN

A collection can be made common to different workspaces. Click on the share button(along with the triple-dot) and then share the collection to any of the workspaces you want.

postman-collection-share-button

postman-share-collection

Getting data from CSV and JSON Files

In this section, we shall see how we can create variables in POSTMAN and then get those variables from a CSV file. A CSV file is a file which contains all the values separated by a comma(,). And so the CSV is the acronym for comma-separated values.

First, create global variables that can be substituted in the request URL and in the body. To create global variables first go to the manage environment icon on the top-right corner on the homepage of the POSTMAN software. And then, go to globals and input the variables.

postman-manage-environment

Then, go to globals:

postman-create-global-variables

Now, enter the variable names and enter the corresponding values. I have named my variables as- endpoint, email, and password.

postman-global-variables-edit

Now, go back to the request page and then replace the endpoint values with the variable name in the URL bar. And also replace the values in the body with the appropriate variable name.

postman-variable-replacement-done

Now, save and send the request and see whether the request is generating the same response.

postman-same-response-after-variables

Now, you have seen that variables can be used in request URL as well as in the body.

Now, we shall see how to get the same values from a CSV file. That is we shall create a CSV(Comma Separated Value) file and will have some values like: end-point, email and password.

Now, just go to any folder or location of your computer and create a file called data01.csv

postman-csv-file

Now, save the file in any location you want and reopen in any text editor and just put a (,) after all the values inside. This is done to indicate a CSV(comma-separated value) file. In case, not separated by a comma, there can be a format related error at the time of running the collection.

I have used notepad++ software to open the file and edit it.

postman-csv-values

Now, to the collection runner and address the CSV file there:

postman-collection-runner-select-file

Now, run the collection by clicking the Run Collection button on the same page.

postman-collection-run-request-body

Now, the response, along with all the details can also be exported into any folder you want. Just click on the export button on the top-right corner of the collection runner page and export the file.

postman-export-result

Now, the location, you selected at the time of saving, check on that location for your exported file.

postman-collection-file-export

postman-exported-file-demo

Similarly, the way to import data from a json file is also the same. Just write the script in a text file, save as a json file, and address the file in the collection runner.

This is how a json file looks like. There are three values- endpoint, email and password.

postman-json-file

Now, select your file in the Collection runner window:

postman-json-file-upload

postman-collection-run-request-body

The report file can be exported in a similar way as we did.

Running POSTMAN Collection Remotely

To run a POSTMAN Collection remotely, just go to the collection you want to run and select the triple-dot button right to the collection name. In the options, you will get share button.

postman-collection-share

Click into the button and you must see a window popping out. Select the Getlink button from there.

postman-getlink-option-copy

Now, copy the link and go to your command prompt.

Now, type: newman run your_copied_link. And hit enter.

Output :

C:UsersHP>newman run https://www.getpostman.com/collections/664090bd3c82e2ecb4d5
newman: Newman v4 deprecates support for the v1 collection format
  Use the Postman Native app to export collections in the v2 format

newman

collection-test01

→ new01
  POST https://reqres.in/api/users?page=2&email=eve.holt@reqres.in [201 Created, 690B, 1740ms]

┌─────────────────────────┬─────────────────────┬─────────────────────┐
│                         │            executed │              failed │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│              iterations │                   1 │                   0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│                requests │                   1 │                   0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│            test-scripts │                   1 │                   0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│      prerequest-scripts │                   1 │                   0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│              assertions │                   0 │                   0 │
├─────────────────────────┴─────────────────────┴─────────────────────┤
│ total run duration: 2.2s                                            │
├─────────────────────────────────────────────────────────────────────┤
│ total data received: 100B (approx)                                  │
├─────────────────────────────────────────────────────────────────────┤
│ average response time: 1740ms [min: 1740ms, max: 1740ms, s.d.: 0µs] │
└─────────────────────────────────────────────────────────────────────┘

As shown above, all the details are displayed in the command line itself.

Adding SOAP Request in POSTMAN

Go to the Google Search bar and type: wsdl country info. Then click on the first link or click the link: http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL. After clicking the link, you must see as below:

postman-soap-url

Then add an extension into the chrome called: Wizdler extension.

postman-wizdler-extension

Once, you have added the extension into the chrome, open the above SOAP link again and then click on the extension.

postman-wsdl-extension-icon

Now, select any of the options under the Country info service. I shall consider the first option, CapitalCity. As you click on the capital city, you must see the below page:

postman-city-info

Now, in change the [string] into IN. (Country Code). And edit the code into the body of the request.

postman-request-body

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <CapitalCity xmlns="http://www.oorsprong.org/websamples.countryinfo">
            <sCountryISOCode>IN</sCountryISOCode>
        </CapitalCity>
    </Body>
</Envelope>

Now, click on the send button and you should see as below:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <m:CapitalCityResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
            <m:CapitalCityResult>New Delhi</m:CapitalCityResult>
        </m:CapitalCityResponse>
    </soap:Body>
</soap:Envelope>

As above you can see that the IN has been changed into New Delhi.

Refer one data from one response to another API

It is possible to get the data from one response of an API and fetch the same data into a different API. Now, let us see how you can do it.

First of all, you have to create two different requests. I shall use the same collection, and inside it I shall create two API requests. One is the GET type and the other is a POST type. The way to create the API request is the same. Visit the same link- https://reqres.in/. And select the requests.

For the first API request, select the GET: List User. Then copy the URL and also the request endpoint and then create the request. (This is your first request).

postman-get-list-users

Now, paste it into the URL bar of the first request and create your first request and name it. I have named it as: list-user.

Now, create the second request. Visit the link: https://reqres.in/ And then select the PUT: Update.

postman-put-update-user

Copy the URL and the request end-point and paste it into the URL bar of your second request. I have named it as: update-user.

Now, you have created both the requests.

postman-create-two-requests

Now, the next step is to parameterize the value in the body section of the request. Go to the second request (update user) and navigate to the body section and then select the raw. Then select a field and replace it with a variable.

So, my original content of the body was:

{
    "name": "morpheus",
    "job": "zion resident"
}

And now I have to change the morpheus into username01.

{
    "name": "{{username01}}",
    "job": "zion resident"
}

Now, the username01 is a variable and has to be updated as a global variable or environment variable. I shall select the environment variable.

To set an environment variable to go to the Manage environment (gear icon) in the top-right corner or create a new environment by clicking on the New button.

postman-environment-variable-set-up

Now, click on the send button and see the output. As you can see below, the name which morpheus earlier is now changed to rahul

postman-name-changed

Fetching data from API Response

Now, to fetch the data from the API response, navigate to the first API response. And go the Tests option. And edit the below code there:

bodyData = JSON.parse(responseBody)
value = bodyData.data[3].first_name
console.log(value)

The data[3].first_name is the path of the first name. So, to get the path, visit: http://jsonpathfinder.com/ and then paste the response test into the editor of the website and then navigate into the right-side of the same page to get the path:

postman-copy-list-user-body

Now, paste it into the json Path finder.

postman-text-pasting

Now, click into data, of the attributes and the corresponding path will be available above in the path bar. Then copy the path.

postman-path-finder-data-path-copied

Now, also you can set variables as Global Variables. As there are different snippets available into the POSTMAN interface itself, you can use it simply and write the code for Global Variable.

postman-set-env-variable-snippet

Now edit the below code into the Text section of your second API request:

bodyData = JSON.parse(responseBody)
value = bodyData.data[3].first_name
console.log(value)
pm.environment.set("username01", value);

After that, save it, and click on the send button. And now check into your current environment, whether the variable has automatically taken the value:

postman-environment-variable-update

............................

Running from JENKINS

In this section, we shall see:

  • How to setup job in Jenkins.
  • How to run POSTMAN from Jenkins.

Before you start using Jenkins, the Jenkins software must be installed in your system.

Download Jenkins: Visit the official page of Jenkins: https://jenkins.io/download/

postman-jenkins-installation-page

Now, click and download the .war file. (for windows users).

Once the file gets downloaded, just create any folder on the desktop(optional) and move the jenkins.war file into that folder.

I have named my folder as jenkins.(you may use any name.). Now open the command prompt and change the path to the same jenkins folder directory.

postman-cmd-jenkins-folder

Now, type the following command: java -jar jenkins.war.

Now, you should see that the jenkins set-up has started in the command prompt itself.

postman-jenkins-setup-started

.

.

Subscribe to See Videos

Subscribe to my Youtube channel for new videos : Subscribe Now