Using Postman with k6.

RiaNaik
4 min readOct 4, 2023

--

We all have used Postman for one use or other. In this blog I have written my experience of using postman to load test using k6.

First, we need is a collection of API requests. Now what is collection in Postman? Postman Collections are groups of saved requests. You can use collections to organize and group your requests. They can then be run together.

We will use this functionality to our use, and we will export the collection and pass it to a tool that converts this collection to k6 scripts. Let’s see how we can do that.

Creating collections in Postman.

  • You must have noticed that whatever requests that you make appear on the left side panel of Postman, we will use that to our advantage and create a collection out of it.
  • If you are trying it out for the first time then, log in to postman and then you can see the create collections button, you can name your collection and give brief description about what it contains.
Collection name and Description.

Once you have created a collection, let's start adding out API requests into it.

# Creating API requests in Collection:

For our example here I have used reqres.in a hosted REST-API.

  • You can choose any requests you want to put in the collection. I have created an example with basic CRUD operation.
Get Request
  • In the above image, we can see the response to the GET request. We can also see status as 200 OK and we can also name our API too for ease of understanding.
  • Let’s look into POST operation, where we will create user via JSON as body given to the API.
POST request
  • When you navigate to Body tab, you can select “raw” and after that you can select the type of body you want to give from the dropdown. I have selected JSON and provided with JSON body.
  • You can observe that on the left panel the requests are being captured only after you save it.
All requests

# Exporting the collection.

  • Now, when our collection is ready let’s export our collection and convert them to k6 script. We will achieve that via the postman-to-k6 tool.
Exporting the collection
  • Clicking on the 3 dots, you can see the above menu and select “Export”.
  • You will be redirected to “Export Collection” dialog, where you can choose the version you want your collection to be in.
Export Collection dialog
  • Save it to the folder of your choice from where you want to run your k6 script.
  • Download the postman-to-k6 tool mentioned above by clicking on the link and following the instructions given there for installation.
  • Once the installation is complete, navigate to the folder where your exported json is located if not already there.
  • Run the following command to convert your collection to k6 script.
$ postman-to-k6 <your-collection.json> -o k6-script.js
  • You will get k6 script as the output and then you can run them via k6.
$ k6 run k6-script.js
  • You can change the script before running as per your need, add environment variables, etc. Check out the official documentation for making changes in the k6 script here.

You can also checkout my github page for the collection that I have used.

--

--