Proactive API performance testing and monitoring are vitally important within web application development. Postman is one of the most popular API testing tools that allows web developers to create collections of calls with input data to an API and check the accuracy of the output data. In this article we will discuss a way to define and use Postman environment variables in Dotcom-Monitor tests.
If you use Postman to test your API services, and you want to automate your tests and continuous monitoring, the Dotcom-Monitor platform provides you with comprehensive solutions and tools to create and run API load tests and monitoring task using Postman Collections. To learn how to set up an API load test using Postman Collections in our load testing solution, LoadView, read our Web API Load Testing with Postman Collection. To learn more about setting up monitoring devices, see our Postman Monitoring (Collection Tasks) with Dotcom-Monitor APIs article.
Postman Variables
Environment variables can be defined by clicking on the eye icon in the upper-right corner of the Postman window (see the Postman learning center website for details). The variables allow developers to store and reuse parameter values in API requests and scripts. If you need to update a variable value, you can do it in one place and the value will be automatically changed throughout your request collections. The environment variables in Postman can be used in the URLs, in the POST parameters, in the JavaScript code, etc. To specify the variable, use the brackets as a variable name placeholder:
{{<variable>}}
Since variables exist separately from request collections in Postman, the values of the variables are not passed together with a Postman collection upon import to Dotcom-Monitor. To address this issue Dotcom-Monitor introduces a Postman Variables import functionality.
Importing Postman Variables to Dotcom-Monitor
If you have been using environment variables to run a collection of requests in Postman, you can import the list of the variables from Postman to Dotcom-Monitor in a few simple steps:
- First, export the list of variables from Postman to a JSON file.
- In Dotcom-Monitor, go to the corresponding Postman Collection task edit page.
- On the Targets sidebar, click the menu button and select Manage Context Parameters.
- In the Manage Context Parameters, click Import and provide the JSON file with the list of variables exported from Postman.
- Click Done. Once imported, the variables will be automatically added to the list of context parameters.
Once the Postman Collection test has been saved, the system will use the provided context parameter’s value in the API request.
Defining Context Parameters for Postman Collections in Dotcom-Monitor
To manually define a new variable in Dotcom-Monitor, you need to create a context parameter associated with this variable:
- On the Task Configuration sidebar, click the actions menu button and select Manage Context Parameters.
- Click Add Parameter and specify the exact same name of the variable as it appears in the uploaded Postman collection. Otherwise, the variable will be parsed as text.
- Specify a value of the variable in the corresponding input field and click Done.