Home

Awesome

<div align="center">

postman-to-k6-cover

</div>

Postman-to-k6

Converts a Postman collection to a k6 script.

The postman-to-k6 converter utilizes your Postman collection and converts all the Postman requests, including tests, variables, ... to K6 scripts that can be executed by K6 to run performance tests.

Github badge <a href="https://www.npmjs.com/package/@apideck/postman-to-k6" alt="Latest Stable Version">npm</a> <a href="https://www.npmjs.com/package/@apideck/postman-to-k6" alt="Total Downloads">npm</a>

This project is a friendly fork of the original grafana/postman-to-k6 converter, actively maintained and open for new contributions.

Feel free to contribute or pass any suggestion to improve postman-to-k6.

Content

Features

Installation

Local Installation (recommended)

While possible to install globally, we recommend that you, if possible, add the converter to the node_modules of your test project using:

$ npm install -D @apideck/postman-to-k6

or using yarn...

$ yarn add @apideck/postman-to-k6

Note that this will require you to run the converter with npx @apideck/postman-to-k6 your-postman-file or, if you are using an older versions of npm, ./node_modules/.bin/postman-to-k6 your-postman-file.

Global Installation

$ npm install -g @apideck/postman-to-k6

Usage

To convert an exported collection to a k6 script:

$ postman-to-k6 collection.json -o k6-script.js

Then run the script in k6, as usual, using:

$ k6 run k6-script.js

Video Introduction

Together with Nicole van der Hoeven & Paul Balogh from the K6 team, we talked about "postman-to-k6" in the K6 Office Hours podcast. We talked about how to convert a Postman collection to a k6 load test, the advantages of Postman, and the benefits of reusing automation testing scripts for performance.

<a href="https://www.youtube.com/watch?v=Be66Db4wHLA" target="_blank" title="Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)" rel="nofollow"> <img src="https://raw.githubusercontent.com/apideck-libraries/postman-to-k6/main/assets/youtube-still.png" alt="Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)" width="50%"></a>

Watch it on Youtube >> https://www.youtube.com/watch?v=Be66Db4wHLA

Topics covered:

Options

Iterations

Configures how many times the script will be executed before completion.

FlagVerboseDefault
-i--iterations1

Example:

$ postman-to-k6 collection.json --iterations 25 -o k6-script.js

Environment Variables

Provide environment variables from a JSON file.

FlagVerboseDefault
-e--environmentN/A

Example:

$ postman-to-k6 collection.json --environment environment.json -o k6-script.js

Global Variables

Provide global variables from a JSON file.

FlagVerboseDefault
-g--globalN/A
$ postman-to-k6 collection.json --global globals.json -o k6-script.js

CSV Data File

Provide a data file in the CSV format.

FlagVerboseDefault
-c--csvN/A
$ postman-to-k6 collection.json --csv data.csv -o k6-script.js

JSON Data File

Pass in a data file in the JSON format.

FlagVerboseDefault
-j--jsonN/A
$ postman-to-k6 collection.json --json data.json -o k6-script.js

K6 Param Options File

Pass K6 parameter options as a file in JSON format.

FlagVerboseDefault
--k6-paramsN/A
$ postman-to-k6 collection.json --k6-params k6-params.json -o k6-script.js

K6 Handle Summary as JSON

Output the K6 summary as a file in JSON format. This will add the K6 handleSummary(data) to the generated script, providing the functionality that K6 will store the summary output as JSON file locally.

FlagVerboseDefault
--k6-handle-summary-jsonN/A
$ postman-to-k6 collection.json --k6-handle-summary-json summary-report.json -o k6-script.js

K6 Request tag

Generate K6 request name tags based on available naming strategies:

FlagVerboseDefault
--k6-request-taggingN/A

Example for request strategy

$ postman-to-k6 collection.json --k6-request-tagging=request -o k6-script.js

Example for folder-request strategy

$ postman-to-k6 collection.json --k6-request-tagging=folder-request -o k6-script.js

Separate

Split requests into separate files, for easier rearrangement of the logic.

FlagVerboseDefault
-s--separatefalse
$ postman-to-k6 collection.json --separate -o k6-script.js
$ postman-to-k6 collection.json -s -o k6-script.js

Skip Pre

Skips any pre-request scripts during conversion

FlagVerboseDefault
--skip-prefalse
$ postman-to-k6 collection.json --skip-pre -o k6-script.js

Skip Post

Skips any post-request scripts during conversion

FlagVerboseDefault
--skip-postfalse
$ postman-to-k6 collection.json --skip-pre -o k6-script.js

CLI options file

Manage all the CLI options in a separate configuration file and pass them along to the postman-to-k6 command. To make the CLI usage easier, especially in CI/CD implementations.

All the available CLI options can be used in the config file. By passing the CLI options as parameters, you can overwrite the defined CLI options defined in the file.

FlagVerboseDefault
--cli-options-filefalse
$ postman-to-k6 collection.json --cli-options-file cli-config.json

Example of JSON CLI config file

{
    "output": "k6-script.js",
    "k6-params": "config/k6-params.json",
    "environment": "config/envs/team.env.json",
    "separate": true
}

Examples

A collection of Postman examples are located under example. To run one of the examples, just run it as you would any other command:

$ postman-to-k6 example/v2/echo.json -o k6-script.js

Unsupported Features

Resources

A collection of blog posts and resources about postman-to-k6

Other similar tools

Credits

Special thanks to the K6 team from Grafana for open-sourcing & growing the converter and contributing it to the community. Thanks to bookmoons for creating this tool. Also, thanks to borjacampina for creating the original incarnation of the tool.