Convert a Postman collection to k6 JavaScript
npm install @aegrey/postman-to-k6
Due to the lack of feature support in the original library and the apideck fork, I have decided to build this out seperately as I require these features immediately in a project I'm working on. I will focus on building out new features not currently supported alongside maintenance
This project is a friendly fork of apideck-libraries/postman-to-k6 from the original grafana/postman-to-k6.
#### Request a New Features
Open an issue with your feature request (must me something currently supported in postman) and I'll work on the requests with the most votes in order.
Also feel free to contribute or pass any suggestions along!
---
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.
- Features
- Installation
- Local Installation (recommended)
- Global Installation
- Usage
- Video introduction
- Options
- Iterations
- Environment Variables
- Global Variables
- CSV Data File
- JSON Data File
- K6 Param Options File
- K6 Handle Summary as JSON
- K6 Request tag
- Separate
- Skip Pre
- Skip Post
- CLI options file
- Examples
- Unsupported Features
- Other similar tools
- Credits
- [x] Pre-request scripts.
- [x] Test scripts.
- [x] Variables (at all scopes + dynamic).
- [x] Data files.
- [x] Authentication methods (except Hawk).
- [x] File uploads (experimental).
- [x] postman.* interface (exceptions below).
- [x] pm.* interface (exceptions below).
- [x] Support for
Postman Dynamic Variables
& ReplaceIn
function.
- [x] Global variables exposed by Postman: globals environment data
iteration.
- [x] xml2Json conversion.
- [x] 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:
``shell`
$ npm install -D @aegrey/postman-to-k6
or using yarn...
`shell`
$ yarn add @aegrey/postman-to-k6
Note that this will require you to run the converter with npx @aegrey/postman-to-k6 your-postman-file or, if you are./node_modules/.bin/postman-to-k6 your-postman-file
using an older versions of npm, .
`shell`
$ npm install -g @aegrey/postman-to-k6
To convert an exported collection to a k6 script:
`shell`
$ postman-to-k6 collection.json -o k6-script.js
Then run the script in k6, as usual, using:
`shell`
$ k6 run k6-script.js
Configures how many times the script will be executed before completion.
| Flag | Verbose | Default |
| ---- | -------------- | ------: |
| -i | --iterations | 1 |
Example:
`shell`
$ postman-to-k6 collection.json --iterations 25 -o k6-script.js
Provide environment variables from a JSON file.
| Flag | Verbose | Default |
| ---- | --------------- | ------- |
| -e | --environment | N/A |
Example:
`shell`
$ postman-to-k6 collection.json --environment environment.json -o k6-script.js
Provide global variables from a JSON file.
| Flag | Verbose | Default |
| ---- | ---------- | ------- |
| -g | --global | N/A |
`shell`
$ postman-to-k6 collection.json --global globals.json -o k6-script.js
Provide a data file in the CSV format.
| Flag | Verbose | Default |
| ---- | ------- | ------- |
| -c | --csv | N/A |
`shell`
$ postman-to-k6 collection.json --csv data.csv -o k6-script.js
Pass in a data file in the JSON format.
| Flag | Verbose | Default |
| ---- | -------- | ------- |
| -j | --json | N/A |
`shell`
$ postman-to-k6 collection.json --json data.json -o k6-script.js
Pass K6 parameter options as a file in JSON format.
| Flag | Verbose | Default |
| ---- | ------------- | ------- |
| | --k6-params | N/A |
`shell`
$ postman-to-k6 collection.json --k6-params k6-params.json -o k6-script.js
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.
| Flag | Verbose | Default |
| ---- | -------------------------- | ------- |
| | --k6-handle-summary-json | N/A |
`shell`
$ postman-to-k6 collection.json --k6-handle-summary-json summary-report.json -o k6-script.js
Generate K6 request name tags based on available naming
strategies:
- none: no automatic generated tags | default
- request: uses the request name as tag (example "Show all accounts")folder-request
- : uses Postman folder name and the request name (example: "Accounts - Show all accounts")
| Flag | Verbose | Default |
| ---- | ---------------------- | ------- |
| | --k6-request-tagging | N/A |
Example for request strategy
`shell`
$ postman-to-k6 collection.json --k6-request-tagging=request -o k6-script.js
Example for folder-request strategy
`shell`
$ postman-to-k6 collection.json --k6-request-tagging=folder-request -o k6-script.js
Split requests into separate files, for easier rearrangement of the logic.
| Flag | Verbose | Default |
| ---- | ------------ | ------- |
| -s | --separate | false |
`shell`
$ postman-to-k6 collection.json --separate -o k6-script.js
`shell`
$ postman-to-k6 collection.json -s -o k6-script.js
Skips any pre-request scripts during conversion
| Flag | Verbose | Default |
| ---- | ------------ | ------- |
| | --skip-pre | false |
`shell`
$ postman-to-k6 collection.json --skip-pre -o k6-script.js
Skips any post-request scripts during conversion
| Flag | Verbose | Default |
| ---- | ------------- | ------- |
| | --skip-post | false |
`shell`
$ postman-to-k6 collection.json --skip-pre -o k6-script.js
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.
| Flag | Verbose | Default |
| ---- | -------------------- | ------- |
| | --cli-options-file | false |
`shell`
$ postman-to-k6 collection.json --cli-options-file cli-config.json
Example of JSON CLI config file
`json`
{
"output": "k6-script.js",
"k6-params": "config/k6-params.json",
"environment": "config/envs/team.env.json",
"separate": true
}
A collection of Postman examples are located under example. To run one of the examples, just run it as you would any
other command:
`shell`
$ postman-to-k6 example/v2/echo.json -o k6-script.js
- Sending requests from scripts using pm.sendRequest.postman.setNextRequest
- Controlling request execution order using .hostOnly
- Cookie properties, like , session, and storeId.responseCode.name
- Textual response messages:
- responseCode.detail
- pm.response.reason
- pm.response.to.have.status(reason)
- pm.response.to.not.have.status(reason)
- pm.request.url
- Properties returning Postman classes:
- pm.request.headerspm.response.headers
- Some features of pm.response.headers.get()
- supported as of 1.9xmlToJson` method.
- The Hawk authentication method.
- Deprecated
- 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.
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.