-
I have converted a Postman collection to K6 scripts, but the when running K6 to execute the K6 scripts |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
When you run K6, you can add a debug option
This will give you some insights into the actual HTTP requests being made. Common issuesCommon issues to review:
Missing headersA missing HTTP header can have a big impact on how your API reacts to requests like authentication header or content-type, so it is important that HTTP headers are included in the K6 requests. Some explanation:
Possible solutions:
An example of a "k6-params.json": {
"maxRedirects": 6,
"headers": {
"Content-Type": "application/json"
}
} And then use it like this when converting your postman collection to K6 scripts.
Missing variablesIn Postman you can use "variables" to define values, even on several levels: Globally (applicable for the complete collection), Environment (variables defined per environment, so that you can easily swap between a DEV & PROD API setup). To pass Postman variables to the K6 scripts, you can have them injected during conversion: You can export your Environment variables from Postman and use the locally saved JSON file (ex:
Example of an exported Postman environment {
"id": "c5a7595b-2001-4482-bae3-c7db15705a8e",
"name": "K6 Office Hours",
"values": [
{
"key": "USERNAME",
"value": "test@example.com",
"enabled": true
},
{
"key": "PASSWORD",
"value": "superCroc2020",
"enabled": true
},
{
"key": "FIRSTNAME",
"value": "John",
"enabled": true
},
{
"key": "LASTNAME",
"value": "Doe",
"enabled": true
},
{
"key": "EMAIL",
"value": "test@example.com",
"enabled": true
},
{
"key": "ACCESS",
"value": null,
"enabled": true
},
{
"key": "REFRESH",
"value": null,
"enabled": true
},
{
"key": "CROCID",
"value": null,
"enabled": true
},
{
"key": "baseUrl",
"value": "http://localhost:3000",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2022-02-24T12:07:22.073Z",
"_postman_exported_using": "Postman/9.13.2"
} which result in: // Auto-generated by the postman-to-k6 converter
import "./libs/shim/core.js";
import { group } from "k6";
export let options = { maxRedirects: 4};
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
collection: {
baseUrl: "http://localhost:3000"
},
environment: {
USERNAME: "test@example.com",
PASSWORD: "superCroc2020",
FIRSTNAME: "John",
LASTNAME: "Doe",
EMAIL: "test@example.com",
ACCESS: null,
REFRESH: null,
CROCID: null,
baseUrl: "http://localhost:3000"
}
});
... |
Beta Was this translation helpful? Give feedback.
When you run K6, you can add a debug option
k6 run --http-debug="full k6-script.js
This will give you some insights into the actual HTTP requests being made.
Common issues
Common issues to review:
Missing headers
A missing HTTP header can have a big impact on how your API reacts to requests like authentication header or content-type, so it is important that HTTP headers are included in the K6 requests.
Some explanation: