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.
Install:
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
A collection of Postman examples are located under example
.
$ postman-to-k6 example/v2/echo.json -o k6-script.js
- 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.
- jmeter-to-k6: Convert JMeter JMX files to k6 JS.
Thanks to bookmoons for creating this tool. Also, thanks to borjacampina for creating the original incarnation of the tool.