Skip to content

Converts Postman collections to k6 script code

License

Notifications You must be signed in to change notification settings

timai89/postman-to-k6

 
 

Repository files navigation

postman-to-k6 CircleCI branch

Convert a Postman collection to k6 script.

Supported Features:

  • Prerequest scripts.
  • Test scripts.
  • Variables (at all scopes + dynamic).
  • Data files.
  • Authentication methods (except Hawk).
  • postman.* interface (exceptions below).
  • pm.* interface (exceptions below).
  • Global variables exposed by Postman: globals environment data iteration.
  • xml2Json conversion.
  • All Postman Schema versions.

Usage

Install:

npm npm dockerhub

Globally, and preferably using nvm (at least on Unix/Linux systems to avoid filesystem permission issues when using sudo):

npm install -g postman-to-k6

Locally, into ./node_modules:

npm install postman-to-k6

Note that this will require you to run the converter with node node_modules/postman-to-k6/bin/postman-to-k6.js ....

Alternatively, you can install the tool from DockerHub:

docker pull loadimpact/postman-to-k6

Convert:

Pass a collection export to convert.

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

The default script runs 1 iteration. Increase if desired.

postman-to-k6 collection.json -i 25 -o k6-script.js

Provide environment and global variable exports separately.

postman-to-k6 collection.json -g globals.json -e environment.json -o k6-script.js

You can also pass a data file in CSV format.

postman-to-k6 collection.json --csv data.csv -o k6-script.js

Or a data file in JSON format.

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

Using the Docker image, you execute the tool as follows:

docker run -it -v "/path/to/postman/collection/:/postman/" loadimpact/postman-to-k6 /postman/MyCollection.postman_collection.json -o /postman/test.js

and then execute the k6 test using:

k6 run /path/to/postman/collection/test.js

Examples

A collection of Postman examples are located under example.

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

Unsupported Features

  • Sending requests from scripts: pm.sendRequest
  • Controlling request execution order: postman.setNextRequest
  • Cookie properties: hostOnly session storeId
  • Textual response message: responseCode.name responseCode.detail pm.response.reason pm.response.to.have.status(reason) pm.response.to.not.have.status(reason)
  • Properties returning Postman classes: pm.request.url pm.request.headers pm.response.headers
  • The Hawk authentication method.
  • Deprecated xmlToJson method.
  • Request IDs are changed. Postman doesn't provide them in the export so we have to generate new ones.

Other similar tools

Credits

Thanks to bookmoons for creating this tool. Also, thanks to borjacampina for creating the original incarnation of the tool.

About

Converts Postman collections to k6 script code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.8%
  • Dockerfile 0.2%