Postman to k6 in under 5 minutes

Rester Test
4 min readJun 13, 2024

Postman is one of the most popular API automation and documentation tools on the market today. You probably are using it yourself.

But after you get confortable with it and have all your test pass you might wonder, as I did, if there is any way to take it to the next level.

What I mean is you have your collection, you have your tests and all is passing, so from a functional point of view all is fine.

But what if you wanted to do more? What if you wanted to make performance testing ( not in Postman) with another QA favorite, K6.

I have the solution for you

The solution is called postman-to-k6.

This is an open-source npm package developed by Apideck that converts Postman collections into k6 scripts. This utility allows developers to leverage their existing Postman tests and effortlessly translate them into performance tests for k6, a powerful open-source load testing tool.

Key Features

  1. Seamless Conversion: postman-to-k6 provides a straightforward way to convert Postman collections (v2.0, v2.1, or v2.1.0 formats) into k6 scripts. This ensures that tests written in Postman can be reused for performance testing without the need to rewrite them from scratch.
  2. Command-Line Interface: The package offers a command-line interface (CLI) that makes the conversion process simple and efficient. With just a few commands, developers can generate k6 scripts from their Postman collections.
  3. Environment Variables Support: It supports environment variables defined in Postman, enabling the seamless transition of environment-specific configurations to k6 scripts. This feature ensures that the generated k6 tests behave consistently with the original Postman tests.
  4. Extensibility: The generated k6 scripts can be further customized and extended to meet specific testing requirements. Developers can add custom logic, incorporate additional k6 features, or modify the scripts to fit their unique scenarios.

Is it hard to use? Can I do it in 5 minutes?

As stated in the title you can do all the steps in about 5 minutes. Do not worry we will perform them all step by step.

Step 1 — Export your postman Collection

In order to convert the tests we first need to export them in a format that k6 understads.

And for that we just need to do export on the collection.

If we have done it correctly then a json will be downloaded to our machine.

Step 2 — Install the plugin

Once we have the export we can proceed to install the plugin. And since the plugin is a node module we would need to use a node project.

We can either use an existing one or create one using npm init and then provide there all the information.

Now in order to install the plugin we just need to do

npm install -g postman-to-k6

Once that is done we will see an entry in our package json

Step3- Perform the conversion

To convert your Postman collection to a k6 script you need to make sure that the json is in the project and then perform this simple command:

postman-to-k6 postman_collection.json -o k6_script.js

Once that has been done your script will be created and you can run the generated k6 script:

k6 run k6_script.js

And if all has been done correctly and the test were run you will see the results.

Step4-Modify and use

Of course once you have your tests exported you can go ahead and change them to your desire. You can customize them for number of users, duration and so forth.

Instead of a Conclusion

Don’t let your Postman tests sit idle. Transform them into powerful load tests with postman-to-k6 and k6.

Write in the comments if you had any issue or if you have any questions!

In case want to learn more visit the postman-to-k6 GitHub repository and get started today.

Your APIs deserve the best, and so do you.

--

--