Postman - Environment, Collection And Monitors

Introduction

In this article, we will look at the concepts of Environments, Collections, and Monitors in postman.

Pre-requisite

Environment

If you are familiar with the concept of the variable in programming, then this concept is easy to grasp.

Postman environment is a way that helps us to store value in the form of variables.

In postman, if we want to store variables value, then we need to create an environment in order to store it.

A collection of key-value pairs is called an Environment. Each name of the variable represents its keys. And referencing the name of the variable allows you to access its value.

Uses of environment

If you want your tests to run against different sets of environment variables like QA, Staging, and Production then we can store the variable values in the environment and then refer the variables in the corresponding request and then run your API Tests.

There are different scopes of variables created in postman,

  • Global
    • These are independent of environments and function outside the environment.
    • Using global variables, we can access data between collections, test scripts, requests, and environments.
  • Collection Variables
    • Collection Variables are independent of environments and are available for all the requests in a collection.
  • Environment
    • These are the most used variable scope in Postman. At a time, a single environment can be active. They are bound to a specified environment used to execute the request.
  • Data
    • Data variables come from external sources like CSV, excel files which you can use it and run your collection.
  • Local
    • These are temporary variables where the scope is only inside the environment they were created.

If we want to create an Environment in postman,

  • Click Environment tile
  • Click new button
  • Provide Environment name
  • Fill the key-value pair and save.

To refer the Environment in API Request,

  • Select the Environment created from the environment dropdown in the right top corner.
  • Refer the key using braces {{<variable key}} and click save.

If you want to create Global variable then,

  • Go to the global section in the environment tile.
  • Fill the key-value pair and save.

To refer to the Global variable in API Request,

  • Refer the key using braces {{<variable key}} and click save.

If you want to create Collection variable then,

  • Click the collection name.
  • You will get several sections, like auth, pre-request script, tests, and variables.
  • Click variables section.
  • Fill the key-value pair and save.
  • Refer the key using braces {{<variable key}} and click save.

Note
In declaring the variables in environment you will have two values initial value and current value

  • The Initial Value is synced to your account using the Postman servers. It's shared with any collaborators who have access to the environment.
  • The Current Value is used in your local instance of Postman, and is never synced to your account or shared with your team

Screenshot of global variable referred,

Postman Environment,Collection and Monitors

Screenshot of collection variable referred,

Postman Environment,Collection and Monitors

Screenshot of environment variable referred,

Postman Environment,Collection and Monitors

Screenshot of collection variable section and its values,

Postman Environment,Collection and Monitors

Screenshot of the environment Tile and its value

Postman Environment,Collection and Monitors

Screenshot of global variable section and its values.

Postman Environment,Collection and Monitors

Collection

  • Collection in Postman means a group of API requests that are already saved in Postman and can be arranged into folders. we can create any number of folders inside a collection.
  •  We can place similar requests into folders and collections which helps the Programmers/Testers in better Organization and Documentation of their requests.
  • APIs requests can be stored and saved within a collection, and these collections can be shared amongst the team using Postman Workspace.

How to create a collection

Create a collection by clicking on the new button from the collection explorer and then click the collection option. Inside the collection click the three dot icon and click add request option,to add the request to the collection.

How to run a collection

We can run the collection using collection runner.

Launch the collection runner by clicking the three dot icon beside the collection name, and then select the run collection option.

In the collection runner,

  1. We can check or uncheck the required API to be run.
  2. We can change the order of API request to be sent before running the collection.
  3. We can provide the number of iterations of all the API inside the collection to be run using the iteration option
  4. We can provide the delay i.e time intervals between execution of each API Request and Response.
  5. If you want to run your collection using data that need to be driven inside the test from CSV or excel file, those things can be configured by clicking the data button and referring the excel or CSV file.
  6. If you want to save the responses after the collection run we can do it by checking the check box save the responses option.

Screenshot of the Collection Runner

Postman Environment,Collection and Monitors

Monitors

Monitors in postman help us to run the collection that are present in postman at a scheduled time.

For example, If I want to run My API Tests at 9 am every morning, we can create Monitors in Postman and set the timing.

Once the monitor is created then the postman will trigger the tests at a scheduled time.

Note that Monitors is a paid feature. you will get charged based on the number of time your monitors run. You can check postman pricing plan to get more information regarding this.

Postman also provides the timezone of different location of the world to schedule your collection.

Steps to Create Monitors

  • Go to Monitors Tile
  • Click Create Monitor
  • Provide Monitor name, select the collection you want to monitor, and select the environment against which you want to run your collection.
  • Provide the data file if you want to drive data into your tests.
  • Next provide the scheduled time to run For Example. which days and at what time your collection needs to run.
  • If you want to receive mail once your Monitor run, you can provide your Mail id in the text box.
  • Next Click the Create Monitor Button.

Your monitor will get created

Screenshot of the monitor section creation:

Postman Environment,Collection and Monitors

Postman Environment,Collection and Monitors

Summary

This article will help you in understanding concepts of Collections, Monitors, and Environments in Postman and how to use them in real-time.

Thanks............