grafana / postman-to-k6 Goto Github PK
View Code? Open in Web Editor NEWConverts Postman collections to k6 script code
License: Apache License 2.0
Converts Postman collections to k6 script code
License: Apache License 2.0
As mentioned in https://community.k6.io/t/problems-load-testing-using-a-postman-collection/432, the postman-to-k6 converter does not currently ship with a shim for escape.
This should be added as 1007 in the k6 repo might still be a while.
Running the converter on the example/v2/twitter.json
collection gives back this error:
Unrecognized OAuth 1.0 signature method: undefined
Error: Unrecognized OAuth 1.0 signature method: undefined
at renderHashFunction (/Users/robin/Projects/loadimpact/postman-to-k6/lib/auth/oauth1.js:158:13)
at new Oauth1Auth (/Users/robin/Projects/loadimpact/postman-to-k6/lib/auth/oauth1.js:40:5)
at authentication (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/Request.js:101:16)
at Request (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/Request.js:32:3)
at Item (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/Item.js:10:3)
at ListMember (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/ListMember.js:12:5)
at module.exports.args (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/ListMember.js:1:40)
at ItemGroup (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/ItemGroup.js:15:5)
at ListMember (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/ListMember.js:10:5)
at module.exports.args (/Users/robin/Projects/loadimpact/postman-to-k6/lib/generate/ListMember.js:1:40)
I suppose this is because I have to provide OAuth credentials, but we should have a more helpful error message saying "To convert this collection you'll have to make sure the correct OAuth credentials are included with the collection.". Alternatively we could perhaps allow auth vars to be set as CLI options, something like:
postman-to-k6 example/v2/twitter.json -o twitter.js --oauth1-consumer-key "KEY" --oauth1-consumer-secret "SECRET" ...
You can pick environment variable names in your JSON file which are illegal javascript variable name. Typical case would be using a dash.
Example:
"key": "client-id"
will become let client-id = "YOUR_VALUE";
{{client-id}}
will become reference to client-id
A very simple fix would be to assign all the variable to an object like env
so we can reuse the illegal names with env['client-id']
. I think it's also nicer anyways because one can then import an env
from another file and reuse environments this way.
I am getting this error when trying to convert a v2 postman collection with nested folder
TypeError: Cannot read property 'body' of undefined
at convertToK6Request (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/lib/postman/k6-generator.js:115:21)
at PostmanItemGroup. (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/lib/postman/k6-generator.js:50:23)
at /Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:2874:23
at /Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:3049:15
at Function. (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:3346:13)
at PostmanPropertyList.each (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/postman-collection/lib/collection/property-list.js:199:11)
at PostmanCollection. (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/lib/postman/k6-generator.js:48:22)
at /Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:2874:23
at /Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:3049:15
at Function. (/Users/hoangle/.nvm/versions/node/v6.10.2/lib/node_modules/postman-to-k6/node_modules/lodash/index.js:3346:13)
Any hint to fix this issue?
I have created the K6 test script using open api generator but while running it getting following error only for delete request:
TypeError: Object has no member 'delete'
Hi,
When we send AWSv4 POST requests using scripts which have been converted from a postman collections using this tool, we should include the stringified body in the signing request as part of the auth
method
body: config.data
in const options
const options = {
method: "POST",
protocol: address.protocol(),
hostname: address.hostname(),
port: address.port(),
path: address.path() + address.search(),
region: `${pm[Var]("awsRegion")}`,
service: `${pm[Var]("awsServiceName")}`,
body: config.data
};
So this generated portion of the script
auth(config, Var) {
const address = new URI(config.address);
const options = {
method: "POST",
protocol: address.protocol(),
hostname: address.hostname(),
port: address.port(),
path: address.path() + address.search(),
region: `${pm[Var]("awsRegion")}`,
service: `${pm[Var]("awsServiceName")}`
};
const credential = {
accessKeyId: `${pm[Var]("AccessKeyId")}`,
secretAccessKey: `${pm[Var]("SecretAccessKey")}`,
sessionToken: `${pm[Var]("SessionToken")}`
};
const signed = aws4.sign(options, credential);
const [path, query = ""] = signed.path.split("?");
config.address = new URI()
.protocol(address.protocol())
.hostname(signed.hostname)
.path(path)
.query(query)
.toString();
Object.assign(config.headers, signed.headers);
}
Would become
auth(config, Var) {
const address = new URI(config.address);
const options = {
method: "POST",
protocol: address.protocol(),
hostname: address.hostname(),
port: address.port(),
path: address.path() + address.search(),
region: `${pm[Var]("awsRegion")}`,
service: `${pm[Var]("awsServiceName")}`,
body: config.data
};
const credential = {
accessKeyId: `${pm[Var]("AccessKeyId")}`,
secretAccessKey: `${pm[Var]("SecretAccessKey")}`,
sessionToken: `${pm[Var]("SessionToken")}`
};
const signed = aws4.sign(options, credential);
const [path, query = ""] = signed.path.split("?");
config.address = new URI()
.protocol(address.protocol())
.hostname(signed.hostname)
.path(path)
.query(query)
.toString();
Object.assign(config.headers, signed.headers);
}
Otherwise we will see the error come back from the API gateway
The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\\n\\nThe Canonical String for this request should have been <redacted>
PS. Thank you for the tool!!!
Only bundle the necessary third-party browserified node.js deps when they're actually needed to fully convert a collection.
A runtime error is observed with a certain collection:
Get : unsupported protocol scheme ""
Reported by @danni-popova in #43.
Postman link: https://www.getpostman.com/collections/f2e5124ce87d5523bd73
i find that some authorization convert fail, like
postman[Request]({
name: "获取产品交付件报告列表",
id: "2220f3e8-724f-41fe-bb5f-db62d882ddef",
method: "GET",
address:
"{{address}}/interface/v3/products/24013871/deliverable/reports?type=WebScan",
headers: {
"x-auth-token":
"ETMsDgAAAXZmUp5GABRBRVMvQ0JDL1BLQ1M1UGFkZGluZwCAABAAEHV5T3VMnz6VqWXXvJbZ2sQAAACA5Ptzl6OtqeUTyKHDEGHlwcdNEE/dgOUtj0Eds3+Kf8KZkIp39mOK+lhLQwyktFZ0nfj+EzV7bIcMLgxTdHP31ZmmkTHx3J0t5hBjmo7MLmWNhQExPuobbTvXFID3m1QAMBAMxyNSec3lqCm6EyTJmwYETZQ1zY1M6ONA67Tx0b8AFKFk3UUEgOH521tBlEBWIRQN4lE4"
}
});
postman[Request]({
name: " 获取工作空间测试报告某版本的质量汇总数据",
id: "adc0824d-ebda-4791-8a35-f496689cbb72",
method: "GET",
address: "{{address}}/interface/v3/products/23046806/quality",
auth(config, Var) {
config.options.x -
auth -
token = "ETMsDgAAAXZmUp5GABRBRVMvQ0JDL1BLQ1M1UGFkZGluZwCAABAAEHV5T3VMnz6VqWXXvJbZ2sQAAACA5Ptzl6OtqeUTyKHDEGHlwcdNEE/dgOUtj0Eds3+Kf8KZkIp39mOK+lhLQwyktFZ0nfj+EzV7bIcMLgxTdHP31ZmmkTHx3J0t5hBjmo7MLmWNhQExPuobbTvXFID3m1QAMBAMxyNSec3lqCm6EyTJmwYETZQ1zY1M6ONA67Tx0b8AFKFk3UUEgOH521tBlEBWIRQN4lE4";
}
});
From the postman POSTrequest with no post data it got converted to following,
http.post(url+"?grant_type=password&username=xyz&password=xyz", { headers: headers });
I have to edit this and also pass body to make it work. Following is the working request,
http.post(url+"?grant_type=password&username=xyz&password=xyz", null, { headers: headers });
Create a Dockerfile and build Docker images on commits and releases to provide an alternative to installing via npm.
posts scripts are still there even adding --skip-post flag
Thanks a lot for implementing this tool, it's very easy to have k6 test script from postman.
And I have a noob question.
Could we add k6 checks to the generated script? And how?
Getting this error / warning. Is there any way to bypass this warning like "node --no-warnings".
(node:50912) ExperimentalWarning: The fs.promises API is experimental
Using Postman Version 7.2.2 with the new graphql
body mode and ran into:
Error: Unrecognized body mode: graphql
Looks like postman-collection
version 3.4.7 supports the new graphql
body mode.
Would love for it to be supported here! Let me know if I can assist with a PR.
Hi,
Firstly thank you for creating this its awesome.
We use a variable in the protocol part of the url (e.g. {{protocol}}://hostname.{{env}}.domain.tld/api/v5/ping
so that we can use env vars to can between http and https for local and server environments. When i convert the the collection the resulting urls come out with the extra protocol, e.g address: "http://{{protocol}}://hostname.{{env}}.domain.tld/api/v5/ping",
which i think is caused by https://github.com/loadimpact/postman-to-k6/blob/master/lib/generate/Request.js#L40
Not sure what the best way round this is?
Hello,
I'm currently giving a try to this tool and when trying to convert one of my Postman projects, I'm encountering the following error:
> postman-to-k6 NodeJS.postman_collection_v2.json
> TypeError: Cannot read property 'count' of undefined
> at PostmanUrl.toString (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\node_modules\postman-collection\lib\collection\url.js:166:24)
> at convertToK6Request (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\lib\postman\k6-generator.js:149:21)
> at K6Generator._convertCollection (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\lib\postman\k6-generator.js:34:19)
> at PostmanCollection.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\lib\postman\k6-generator.js:93:12)
> at C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\node_modules\lodash\index.js:2874:23
> at C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\node_modules\lodash\index.js:3049:15
> at Function.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\node_modules\lodash\index.js:3346:13)
> at PostmanPropertyList.each (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\node_modules\postman-collection\lib\collection\property-list.js:199:11)
> at K6Generator.convert (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\lib\postman\k6-generator.js:91:29)
> at Object.convert (C:\Users\user\AppData\Roaming\npm\node_modules\postman-to-k6\lib\converters\postman-2.0.0.js:12:30)
>
Here's the Postman project, for your reference:
https://pastebin.com/PBnLCA3b
Thanks a lot in advance!
Cheers!
I have generated a script file by using openAPIgenerator but while running it through K6, its skipping some APIs. It is not giving any error. Can you suggest me a way to find out why it is skipping that and how can I debug it?
Example API:
import http from "k6/http";
import { group, check, sleep } from "k6";
const BASE_URL = "http://host:port";
// Sleep duration between successive requests.
// You might want to edit the value of this variable or remove calls to the sleep function on the script.
const SLEEP_DURATION = 0.1;
let body = "";
let file = {"file": http.file(open("D:/test/file.yaml", "b"), "file.yaml")};
let authorization = "";
export default function() {
group("/api/v1/upload-file", () => {
let userId = 2;
let url = BASE_URL + `/api/v1/upload-file`;
// Request No. 1
// TODO: edit the parameters of the request body.
let params = {headers: {"Content-Type": "multipart/form-data", "Authorization": `${authorization}`, "Accept": "*/*"}};
let request = http.post(url, file, params);
check(request, {
"OK": (r) => r.status === 200
});
sleep(SLEEP_DURATION);
});
}
Adding the ability to output the response when running a test, would be really valuable for debugging purposes
post(response) {
console.log(JSON.stringify(response))
}
and the following will allow the output of the response body, which is useful if the output contains useful information
post(response) {
console.log(JSON.stringify(response.body))
}
It would be nice if we could pass a command line option when running postman-to-k6
in order to do this, rather than having to add it in manually after the script is generated.
Not sure if this is preferable or useful to others, but thought I would raise it (happy for it to be closed!)
When using the --separator
like postman-to-k6 postman.json -s -e environment.json -o k6-script.js
A range of folders and files are generated and grouped in the k6-script.js
// Auto-generated by the Load Impact converter
import "./libs/shim/core.js";
import { group } from "k6";
import "./requests/DomainClusters/Get-all-domain-cluster-configurations.js";
export let options = { maxRedirects: 4 };
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
collection: {
undefined: "https://example.com/api"
},
environment: {
baseUrl: "https://example.com/portal"
}
});
export default function() {
group("DomainClusters", function() {
postman[Request]("Get all domain cluster configurations");
});
}
In the Get-all-domain-cluster-configurations.js
file the following code is present
import "./libs/shim/urijs.js";
postman[Symbol.for("define")]({
name: "Get all domain cluster configurations",
id: "cbe7c568-113f-4352-a0cc-bd8326ca9e7d",
method: "GET",
address: "{{baseUrl}}/portal/v1/domainclusters"
});
All files are present in the libs/shim folder.
When I run the k6 run --vus 100 --duration 1m k6-script.js
, I get the following error.
ERRO[0006] GoError: The moduleSpecifier "./libs/shim/urijs.js" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker. at reflect.methodValueCall (native)
Info: I'm not using the Docker version, but installed k6 via Brew and using the 1.1.0 release of postman-to-k6 (which is the latest release according to NPM)
Converting a multipart post script throws an ERR_INVALID_ARG_TYPE
.
jhewitt@JimsMac LoadTest % postman-to-k6 PostmanCollection.json k6-script.js
The "path" argument must be of type string. Received type object
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
at validateString (internal/validators.js:125:11)
at basename (path.js:1289:5)
at fileLoad (/usr/local/lib/node_modules/postman-to-k6/lib/render/index.js:190:16)
at files (/usr/local/lib/node_modules/postman-to-k6/lib/render/index.js:180:18)
at render (/usr/local/lib/node_modules/postman-to-k6/lib/render/index.js:20:5)
at convertObject (/usr/local/lib/node_modules/postman-to-k6/lib/convert/object.js:45:10)
at convertJson (/usr/local/lib/node_modules/postman-to-k6/lib/convert/json.js:26:10)
at convertFile (/usr/local/lib/node_modules/postman-to-k6/lib/convert/file.js:31:10)
at Command.run (/usr/local/lib/node_modules/postman-to-k6/bin/postman-to-k6.js:51:30)
at Command.listener (/usr/local/lib/node_modules/postman-to-k6/node_modules/commander/index.js:315:8)
The postman script being converted is as follows:
{
"info": {
"_postman_id": "53810ff5-fa40-4971-9d83-9e0d7ef1f8a6",
"name": "Quidel Load Testing",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Post Assay, Both Images - Flu A Positive",
"event": [
{
"listen": "test",
"script": {
"id": "53f8e350-9de2-4cbb-9007-f16dc329e525",
"exec": [
"pm.test(\"Status Test\", () => {",
" pm.response.to.have.status(201);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"id": "8b675d75-b02a-4cab-99d8-1c1112620ca6",
"exec": [
"require('lodash');",
"pm.environment.set(\"barcodeData\", Math.floor(_.random(10000000000000000000000000000000000000000000000, 99999999999999999999999999999999999999999999999)).toLocaleString('fullwide', {useGrouping: false}));"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "api-key",
"value": "B051ED42-72C5-435A-B383-2D92346A9B6D",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "assayJson",
"value": "{\n assayJson : {\n barcodeData: \"18382871446225358000000000000000000000000000000\",\n barcodeType: 1,\n userId: \"postman\",\n appVersion: \"postman\",\n phoneId: \"Postman\",\n phoneOs: \"Postman\",\n expirationDate: \"1/1/2020 12:00:00 AM\",\n serialNumber: \"872930\",\n auxBoxId: \"1234\",\n assayType: \"90\",\n testDate: \"1/1/2020 12:00:00 AM\",\n results : [\n {\n type: \"fluBProb\",\n value: \"0.85\"\n },\n {\n type: \"fluAProb\",\n value: \"0.75\"\n },\n {\n type: \"rcPeakValue\",\n value: \"100\"\n },\n {\n type: \"fluAResult\",\n value: \"positive\"\n },\n {\n type: \"fluBResult\",\n value: \"negative\"\n }\n ],\n images : [\n {\n type: \"lightImage\",\n fileName: \"18645_d1fd_DIMG_20201103T2218_5a8a345b-68b2-48f6-b537-74d084dc56c1.raw\",\n captureTime: \"1/1/2020 12:00:00 AM\"\n },\n {\n type: \"darkImage\",\n fileName: \"18645_d1fd_LIMG_20201103T2218_4672fbab-048f-47b4-8698-4ae31ddf7551.raw\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate1\",\n fileName: \"18645_d1fd_DBRGB_20201103T2218_0d3f5319-49a1-4bf5-b1ce-f6e1a75ac328.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate2\",\n fileName: \"18645_d1fd_DBRD_20201103T2218_4146b8d3-7721-4497-9d21-4de3d3c5959a.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate3\",\n fileName: \"18645_d1fd_NMRGB_20201103T2218_2e21a031-70cb-44a5-9811-992c2dbab6e9.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate4\",\n fileName: \"18645_d1fd_RDCRP_20201103T2218_91be8f98-e335-432a-9c87-81cbd8cc045f.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate5\",\n fileName: \"18645_d1fd_RGBCRP_20201103T2218_af5d97bf-99d9-4f95-b264-6f2ba4db8e3b.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n },\n {\n type: \"intermediate6\",\n fileName: \"18645_d1fd_THBW_20201103T2218_3c660420-4af0-4604-b353-bc96ead36e3c.png\",\n captureTime: \"1/1/2020 12:00:00AM\"\n }\n ]\n }\n}",
"contentType": "application/json",
"type": "text"
},
{
"key": "image[]\n",
"type": "file",
"src": [
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_DBRGB_20201103T2218_0d3f5319-49a1-4bf5-b1ce-f6e1a75ac328.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_DBRD_20201103T2218_4146b8d3-7721-4497-9d21-4de3d3c5959a.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_THBW_20201103T2218_3c660420-4af0-4604-b353-bc96ead36e3c.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_RGBCRP_20201103T2218_af5d97bf-99d9-4f95-b264-6f2ba4db8e3b.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_RDCRP_20201103T2218_91be8f98-e335-432a-9c87-81cbd8cc045f.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_NMRGB_20201103T2218_2e21a031-70cb-44a5-9811-992c2dbab6e9.png",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_LIMG_20201103T2218_4672fbab-048f-47b4-8698-4ae31ddf7551.raw",
"/Users/jhewitt/Source/Quidel/LoadTest/18645_d1fd_DIMG_20201103T2218_5a8a345b-68b2-48f6-b537-74d084dc56c1.raw"
]
}
],
"options": {
"formdata": {}
}
},
"url": {
"raw": "",
"protocol": "https",
"host": [
"sniffles-api-dev",
"azurewebsites",
"net"
],
"path": [
"api",
"v1.0",
"assay",
"postassaywithimages"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
Hi,
I followed the steps to configure k6 on Windows 10 and getting the error: 'k6' is not recognized as an internal or external command.
I have installed k6.exe (x64) and executing the steps in the mentioned order
git clone [email protected]:loadimpact/postman-to-k6.git
cd postman-to-k6
npm install
#On windows
node bin/postman-to-k6.js examples/postman/v2/echo.json
k6 run k6-script.js
Getting error at the last command: k6 run k6-script.js
Support for GraphQL body mode is being added #37. Initial logic supports everything except GraphQL variables.
Update to support GraphQL variables.
I'm using variables for each request and when we do the transformation to k6, the tool adds "http" protocol at the beginning of the URL, so I have http://{{requestUrl}} and the variable have https://url.com and the the request in k6 it became http://https:url.com correction the request url is: http://https://url.com
TL;DR
https://google.com
fetched from a variable should become just that, not http://https://google.com
Hi,
In postman, we typically have a range of CRUD operations (including DELETE).
Our aim is to use the K6 script in a continuous integration Azure pipeline, where after each push to GIT > we convert our OpenApi spec (with examples) to a postman collection > which we convert to a K6 script (using the excellent postman-to-k6) > which we then trigger to execute "K6 run" to run a loadtest
I'm looking for a manner to skip certain POSTMAN operations/paths (like DELETE)
Do you have any pointers?
An alternative could be that, I use the --separate
option (like postman-to-k6 collection.json --separate -o k6-script.js
)and then define in my Azure pipeline which files to execute.
steps:
- task: k6-load-test@0
inputs:
filename: 'k6-script_1.js'
- task: k6-load-test@0
inputs:
filename: 'k6-script_2.js'
Or is there another way to be able to skip certain postman paths from being executed by the K6 run?
We have a system where the POST body can contain formatted data like {{some_string}}
, and this works fine in Postman because when it thinks it finds a variable but that variable does not exist, it defaults to just sending the original string in the request. But this line breaks the API call, because it uses the string undefined
instead of defaulting back to the original.
Replacing undef
with "{{" + name + "}}"
makes this work correctly.
Some dependencies modify prototypes. Since the k6 JavaScript environment doesn't provide Object.setPrototypeOf()
, loading fails for these libraries.
Find a solution.
I'm wondering if it would be possible to push an updated docker image to hub.docker? The latest image I am able to find was last updated a year ago. https://hub.docker.com/r/loadimpact/postman-to-k6
Thank you!
Hi,
I have a lot of "unsupported features" in my postman "Tests".
I thought "--skip-post" has meant to remove those tests scripts from the final k6 script,
but it appears they are still in my k6 script after the conversion (resulting in errors during k6 execution)
Is the tag --skip-post meant to remove the tests or am I misunderstanding the tag ?
If yes, why are the tests script still in the k6-script.js ?
Thanks
As mentioned in:
https://community.k6.io/t/typeerror-object-has-no-member-replace/253
"Hi
I’ve just converted a postman collection through postman-to-k6 tool.
I’m having the current problem when executing the script and it seems to be connected to http.file part
I’m out of clues about what is happening here
code:
export default function() {
postman[Request]({
name: "/recommendation (file upload)",
id: "72996999-1924-45d4-8b65-1e1867785397",
method: "POST",
address: "{{recommendation-url}}/recommendation?start=1&limit=10",
data: { user_id: "5", file: http.file(document_file) },
headers: {
"Content-Type": "application/json"
},
post(response) {
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable(
"recommendation_request.id",
jsonData.recommendation_request.id
);
}
});
Error raised while running the script:
ERRO[0005] TypeError: Object has no member 'replace'
at makeRequestConfig (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:996:205(117))
at executeRequest (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:960:35(78))
at executeRequest (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:956:234(53))
at file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:307:46(35)
at file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/recommendation-k6-script.js:37:19(31)
done [==========================================================] 1 / 1
Thank you in advance"
P.S. It is uploading a word document (binary)
Add a CLI option to output each request in a collection to a separate JS file. Groups should be respected and create necessary folder tree in output directory.
I am able to convert my postman collection to k6 format by load impact converter.
But, how can i generate Load ?
Is my understanding right that this tool will help in load testing as we have a user SLA ?
Installed the tool and ran it against the echo example but when it comes to executing that I get a JS error that seems quite fundamental
❯ npm install -g postman-to-k6
/usr/local/bin/postman-to-k6 -> /usr/local/lib/node_modules/postman-to-k6/bin/postman-to-k6.js
> [email protected] postinstall /usr/local/lib/node_modules/postman-to-k6
> node scripts/bundle.js
+ [email protected]
updated 1 package in 3.456s
❯ postman-to-k6 echo.json -o k6-rg.js
❯ k6 run k6-rg.js
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | (_) |
/ __________ \ |__| \__\ \___/ .io
execution: local
script: k6-rg.js
output: -
scenarios: (100.00%) 1 executors, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
ERRO[0005] TypeError: Cannot read property 'indexOf' of undefined
running at executePostrequest (file:///Users/david/projects/k6.x/libs/shim/core.js:1196:203(90))
default at executeRequest (file:///Users/david/projects/k6.x/libs/shim/core.js:985:25(128))
at executeRequest (file:///Users/david/projects/k6.x/libs/shim/core.js:968:5(57))
at file:///Users/david/projects/k6.x/libs/shim/core.js:307:46(35)
at file:///Users/david/projects/k6.x/k6-rg.js:16:21(28)
at native
at file:///Users/david/projects/k6.x/k6-rg.js:15:17(5) executor=per-vu-iterations scenario=default
running (00m00.6s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.5s/10m0s 1/1 iters, 1 per VU
█ Auth: Digest
data_received..............: 5.7 kB 10 kB/s
data_sent..................: 942 B 1.7 kB/s
group_duration.............: avg=530.41ms min=530.41ms med=530.41ms max=530.41ms p(90)=530.41ms p(95)=530.41ms
http_req_blocked...........: avg=435.83ms min=435.83ms med=435.83ms max=435.83ms p(90)=435.83ms p(95)=435.83ms
http_req_connecting........: avg=95.78ms min=95.78ms med=95.78ms max=95.78ms p(90)=95.78ms p(95)=95.78ms
http_req_duration..........: avg=93.75ms min=93.75ms med=93.75ms max=93.75ms p(90)=93.75ms p(95)=93.75ms
http_req_receiving.........: avg=112µs min=112µs med=112µs max=112µs p(90)=112µs p(95)=112µs
http_req_sending...........: avg=203µs min=203µs med=203µs max=203µs p(90)=203µs p(95)=203µs
http_req_tls_handshaking...: avg=302.85ms min=302.85ms med=302.85ms max=302.85ms p(90)=302.85ms p(95)=302.85ms
http_req_waiting...........: avg=93.43ms min=93.43ms med=93.43ms max=93.43ms p(90)=93.43ms p(95)=93.43ms
http_reqs..................: 1 1.795026/s
iteration_duration.........: avg=530.45ms min=530.45ms med=530.45ms max=530.45ms p(90)=530.45ms p(95)=530.45ms
iterations.................: 1 1.795026/s
I tried installing the tool using the non global as well but it didn't seem to make a difference. Here's the versions I'm using:
❯ k6 version
k6 v0.27.1 (dev build, go1.14.5, darwin/amd64)
❯ postman-to-k6 -V
1.1.0
In Postman, a body can have variables in bracket notation e.g {{my_var}}.
Replacement is currently only performed for url and headers, would it be possible to replace variables in body too?
Trying to convert a Postman collection for the Load Impact API (find Postman collection in this gist) I get this:
Unrecognized body mode: undefined
Error: Unrecognized body mode: undefined
at data (/<path-to>/postman-to-k6/lib/generate/Request.js:61:13)
at Request (/<path-to>/postman-to-k6/lib/generate/Request.js:30:3)
at Item (/<path-to>/postman-to-k6/lib/generate/Item.js:10:3)
at ListMember (/<path-to>/postman-to-k6/lib/generate/ListMember.js:12:5)
at module.exports.args (/<path-to>/postman-to-k6/lib/generate/ListMember.js:1:40)
at ItemGroup (/<path-to>/postman-to-k6/lib/generate/ItemGroup.js:15:5)
at ListMember (/<path-to>/postman-to-k6/lib/generate/ListMember.js:10:5)
at module.exports.args (/<path-to>/postman-to-k6/lib/generate/ListMember.js:1:40)
at Collection (/<path-to>/postman-to-k6/lib/generate/Collection.js:19:5)
at convertObject (/<path-to>/postman-to-k6/lib/convert/object.js:40:3)
@bookmoons Could you have a look at this?
Hi everyone!
I am trying to use the postman-to-k6 converter, but my Postman collections have quite a few unsupported method calls in both Pre-request Scripts and Tests. I don’t really need either for running the load tests, but unless I delete them manually, the runs fail immediately.
Is there any way to automatically skip the conversion of Pre-request Scripts and Tests or at least skip their execution?
Thanks upfront! :slight_smile:
This option definitely makes sense to me.
I think it will be easier to use if there was a docker image instead of installing it with npm
I have postman collections I wish to load test, but my collections are run with the -e option to designate the environment variables it needs. Can this convert collections that also use environment variables and if so, what is the command for that?
I found that the updated value of variable 'counter'
in 'pm.environment' was not be replaced correctly
in the 'request body'.
Value of 'counter' that was set in
the 'pm.environment' variable
should be replaced correctly in
the sent request data.
The 'counter' value of first '/echo/'
request is 'undefined'.
I found that the problem is in below function
at the commented line (line contains pm[Var])
which can be fixed by replace it with
'pm.environment.get'.
function evaluate(string) {
// return string.replace(expression.variables, (match, name) => pm[Var](name));
return string.replace(expression.variables, (match, name) => pm.environment.get(name));
}
When an option is "blank" in Postman, it is exported in this format:
"src": [],
When postman-to-k6 encounters this value, it gives the following error on the command line:
The "path" argument must be of type string. Received type object
Editing the exported collection, changing the [] to "", before converting it works around the problem.
"key": "sampleFile2", "type": "file", "src": [], "disabled": true },
{ "key": "sampleFile2", "type": "file", "src": "", "disabled": true },
i have many apis in postman, postman2k6 and k6 just give the summary of all the apis.
i want to get the duration of each apis,
is there any good ideas?
running (00m14.9s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m14.9s/10m0s 1/1 iters, 1 per VU
█ BaseInfo
█ Product
█ Design
█ Task
█ Service
█ Tools
█ Report
data_received..............: 538 kB 36 kB/s
data_sent..................: 13 MB 851 kB/s
group_duration.............: avg=3.35s min=35.93ms med=1.67s max=11.97s p(90)=8.01s p(95)=9.99s
http_req_blocked...........: avg=3.32ms min=0s med=0s max=130.62ms p(90)=0s p(95)=0s
http_req_connecting........: avg=703.94µs min=0s med=0s max=30.91ms p(90)=0s p(95)=0s
http_req_duration..........: avg=287.33ms min=5.98ms med=238.43ms max=1.9s p(90)=532.75ms p(95)=875.7ms
http_req_receiving.........: avg=476.87µs min=0s med=0s max=9.71ms p(90)=873.8µs p(95)=3.38ms
http_req_sending...........: avg=1.79ms min=0s med=0s max=89.75ms p(90)=0s p(95)=498.25µs
http_req_tls_handshaking...: avg=1.93ms min=0s med=0s max=67.82ms p(90)=0s p(95)=0s
http_req_waiting...........: avg=285.06ms min=5.98ms med=238.43ms max=1.9s p(90)=532.75ms p(95)=830.82ms
http_reqs..................: 51 3.425009/s
iteration_duration.........: avg=14.85s min=14.85s med=14.85s max=14.85s p(90)=14.85s p(95)=14.85s
iterations.................: 1 0.067157/s
vus........................: 1 min=1 max=1
vus_max....................: 1 min=1 max=1
Implement support for v1 of the Postman collection format.
The Postman requests always seems to fallback to the request header "application/x-www-form-urlencoded", when none is specified.
Is there a way to overwrite this behaviour?
Hello. I converted a Postman collection using postman-to-k6 tool and tried to execute the generated script, but got the error message "Missing Postman environment". I used the postman-to-k6 tool before and did not see that message at that time and I think that this would be related to the changes made with #13 but I have no idea what I should do. Any suggestions are appreciated.
rohit@bmdvrohitjai:~/Downloads/k6-v0.17.1-linux32$ ./k6 run Demo_script.js
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | () |
/ __________ \ |__| _\ ___/ Welcome to k6 v0.17.1!
execution: local
output: -
script: /home/rohit/Downloads/k6-v0.17.1-linux32/Demo_script.js (js)
duration: 0s, iterations: 1
vus: 1, max: 1
web ui: http://127.0.0.1:6565/
panic: runtime error: invalid memory address or nil pointer dereference-- / --
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x80492cc]
goroutine 7 [running]:
sync/atomic.AddUint64(0x1a472414, 0x12e, 0x0, 0x1000, 0x12e)
/usr/local/Cellar/go/1.8.3/libexec/src/sync/atomic/asm_386.s:112 +0xc
github.com/loadimpact/k6/lib/netext.(*Conn).Write(0x1a52d870, 0x1a081000, 0x12e, 0x1000, 0x12, 0x857b380, 0x197261c0)
/Users/uppfinnarn/Projects/Go/src/github.com/loadimpact/k6/lib/netext/dialer.go:81 +0x70
net/http.persistConnWriter.Write(0x1a1fc0a0, 0x1a081000, 0x12e, 0x1000, 0xd0, 0x86166be, 0x3)
/usr/local/Cellar/go/1.8.3/libexec/src/net/http/transport.go:1133 +0x3f
bufio.(*Writer).Flush(0x19b92360, 0x88c4dc0, 0x19b92360)
/usr/local/Cellar/go/1.8.3/libexec/src/bufio/bufio.go:566 +0x5d
net/http.(*persistConn).writeLoop(0x1a1fc0a0)
/usr/local/Cellar/go/1.8.3/libexec/src/net/http/transport.go:1709 +0x334
created by net/http.(*Transport).dialConn
/usr/local/Cellar/go/1.8.3/libexec/src/net/http/transport.go:1118 +0x8ac
rohit@bmdvrohitjai:~/Downloads/k6-v0.17.1-linux32$
Issue #12 seems isn't completely solved. Opened forum question here:
https://community.k6.io/t/postman-variables-in-body-wont-get-replaced/113
Seems the answer from tamitakamiya fixes the issue, at least for me.
config.data = data
to
config.data = evaluate(data)
Hi,
I was wondering if it would be possible to define the sleep time between requests in postman ?
I was trying to run my postman to k6 converted script and getting an error while running it. Has anyone faced this issue before?
Hello
First, bravo for this great tool : )
I'am using this to convert all our Postman collection into k6 script, and I had a tons of http 403 response, found out that the generated k6 script does not have a default value for AWS service name, if this field is left empty in the Postman interface.
postman
AWS4-HMAC-SHA256 Credential=XXX/XXX/eu-central-1/execute-api/aws4_request ...
post-to-k6
AWS4-HMAC-SHA256 Credential=XXX/XXX/eu-central-1//aws4_request
A suggestion from me would be to set the default service name value to execute-api
, and eventually for all other value that are auto generated by Postman if left blank.
Regards
We would like to improve the workflow for users of Postman collections (v2.x) that want to load test their APIs using k6, provide an even better onboarding experience to k6 (and in extension Load Impact), by extending the postman-to-k6 converter to take the following Postman collection features into account in the conversion process. A completed solution will also include tests and docs (updated README).
Related issues:
Setting cookies properly if they’re explicitly defined in the collection, see docs.
Relevant links:
Setting up use of client certificates in k6 if defined in the collection, see docs.
Relevant links:
Support the most common authentication options supported by Postman, see docs.
The authentications we want to support:
This should also include the case when the authentication is set to “Inherit auth from parent”.
Relevant links:
Support environment and global variables defined in the collection, see docs. The conversion to k6 JS must make sure to adhere to the scoping rules defined in https://learning.getpostman.com/docs/postman/environments_and_globals/variables/#variable-scopes.
In general variables in the request URL, params, headers and body will have the form {{someVariable}}. These needs to be set by properly resolving the variable.
Relevant links:
The conversion needs to support Postman’s dynamic variables that can be present in the request URL, params, headers and body:
{{$guid}}
: Adds a v4 style GUID{{$timestamp}}
: Adds the current timestamp{{$randomInt}}
: Adds a random integer between 0 and 1000The conversion needs to support what’s called “data variables” in Postman, see docs. This is parameterization data loaded from a CSV or JSON file and then used in request URL, params, headers, body or pre-/post-request scripts.
In scripts you get variables (global, environment, dynamic or data) by using one of the APIs, see Scripting below.
Postman has support for JS scripting in the form of pre-request scripts and post-response test scripts. By providing a shim layer in the converted script to support the Postman Sandbox execution environment, where pre-/post-requests scripts are executed, we should be able to provide a much more useful conversion tool from Postman to k6 for doing load testing.
The shim layer could either be embedded in the converted script (or as a module that the converter spits out and the main file loads) or fetched from k6 github perhaps as a remote import, something like:
import postman from “github.com/loadimpact/k6/master/shims/postman-sandbox.js”;
These are currently appended as comments in the k6 script, but will now need to be inserted into k6 verbatim, with the necessary Postman APIs made available by the shim layer. See pre-request scripts docs and post-request test scripts for more info.
Support both pre-request scripts specified for a collection, a folder and an individual request (respecting the execution order of scripts).
The following Postman Sandbox APIs needs to be supported/shimmed:
postman.getResponseHeader(headerName)
xml2Json(xmlString)
postman.setEnvironmentVariable(variableName, variableValue)
postman.getEnvironmentVariable(variableName)
postman.setGlobalVariable(variableName, variableValue)
postman.getGlobalVariable(variableName)
postman.clearEnvironmentVariable(variableName)
postman.clearGlobalVariable(variableName)
postman.clearEnvironmentVariables()
environment
(a global object variable used by the functions above)globals
(a global object variable used by the functions above){% raw %}{{$guid}}{% endraw %}
: Adds a v4 style GUID{% raw %}{{$timestamp}}{% endraw %}
: Adds the current timestamp.{% raw %}{{$randomInt}}{% endraw %}
: Adds a random integer between 0 and 1000responseCookies
(array variable with response cookies for current response)postman.getResponseCookie(cookieName)
request
(object with request attributes)
data
(key/value form data object)headers
(key/value object with request headers)method
url
responseHeaders
(key/value object with response headers)responseBody
(string, use JSON.parse or xml2json to parse it)responseTime
(number, total response time in milliseconds)responseCode
(object)
code
name
detail
tests
(object with the users “checks”/”asserts”, boolean results of logical tests)iteration
(number, the current test run index)data
(object with parsed CSV or JSON data, each VU and iteration in k6 would need to fetch a new row of data, see this blog post)pm
object, which is only available in Postman, not Newman): https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/
require()
’ing of Nodejs modules, that should result in an error message saying “Can’t load module X, Node.js modules aren’t supported in k6”pm.sendRequest(url|requstObject, callback)
this call would need to be synchronous in k6, so it wouldn’t return until the callback function is done executing.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.