Development and maintenance have been stopped in this repository.
A fork of this project is active and maintained at apideck-libraries/postman-to-k6.
Converts a Postman collection to a k6 script.
- Features
- Installation
- Usage
- Options
- Docker Usage
- Examples
- Unsupported Features
- Other similar tools
- Credits
- Prerequest scripts.
- Test scripts.
- Variables (at all scopes + dynamic).
- Data files.
- Authentication methods (except Hawk).
- File uploads.
postman.*interface (exceptions below).pm.*interface (exceptions below).- Global variables exposed by Postman:
globalsenvironmentdataiteration. xml2Jsonconversion.- All Postman Schema versions.
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 postman-to-k6
# or using yarn...
$ yarn add postman-to-k6Note that this will require you to run the converter with npx 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.
$ npm install -g postman-to-k6The tool is also available for usage in Docker. To download an image with the tool from DockerHub:
$ docker pull loadimpact/postman-to-k6
To convert an exported collection to a k6 script:
$ postman-to-k6 collection.json -o k6-script.jsThen run the script in k6, as usual, using:
$ k6 run k6-script.jsConfigures how many times the script will be executed before completion.
| Flag | Verbose | Default |
|---|---|---|
-i |
--iterations |
1 |
Example:
$ postman-to-k6 collection.json --iterations 25 -o k6-script.jsProvide environment variables from a JSON file.
| Flag | Verbose | Default |
|---|---|---|
-e |
--environment |
N/A |
Example:
$ postman-to-k6 collection.json --environment environment.json -o k6-script.jsProvide global variables from a JSON file.
| Flag | Verbose | Default |
|---|---|---|
-g |
--global |
N/A |
$ postman-to-k6 collection.json --global globals.json -o k6-script.jsProvide a data file in the CSV format.
| Flag | Verbose | Default |
|---|---|---|
-c |
--csv |
N/A |
$ postman-to-k6 collection.json --csv data.csv -o k6-script.jsPass in a data file in the JSON format.
| Flag | Verbose | Default |
|---|---|---|
-j |
--json |
N/A |
$ postman-to-k6 collection.json --json data.json -o k6-script.jsPass K6 parameter options as a file in JSON format.
| Flag | Verbose | Default |
|---|---|---|
--k6-params |
N/A |
$ postman-to-k6 collection.json --k6-params k6-params.json -o k6-script.jsSplit requests into separate files, for easier rearrangement of the logic.
| Flag | Verbose | Default |
|---|---|---|
-s |
--separate |
false |
$ postman-to-k6 collection.json --separate -o k6-script.jspostman-to-k6 collection.json -s -o k6-script.jsSkips any pre-request scripts during conversion
| Flag | Verbose | Default |
|---|---|---|
--skip-pre |
false |
$ postman-to-k6 collection.json --skip-pre -o k6-script.jsSkips any post-request scripts during conversion
| Flag | Verbose | Default |
|---|---|---|
--skip-post |
false |
$ postman-to-k6 collection.json --skip-pre -o k6-script.jsUsing the Docker image, you execute the tool as follows:
$ docker run -it \
-v "/path/to/postman/collection/:/postman/" \
loadimpact/postman-to-k6 \
/postman/my-collection.json \
-o /postman/test.jsand then execute the k6 test using:
$ k6 run /path/to/postman/collection/test.jsA 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- Sending requests from scripts using
pm.sendRequest. - Controlling request execution order using
postman.setNextRequest. - Cookie properties, like
hostOnly,session, andstoreId. - Textual response messages:
responseCode.nameresponseCode.detailpm.response.reasonpm.response.to.have.status(reason)pm.response.to.not.have.status(reason)
- Properties returning Postman classes:
pm.request.urlpm.request.headerspm.response.headers
- The Hawk authentication method.
- Deprecated
xmlToJsonmethod. - 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.