Hi,
I recently started looking for load testing tools other than JMeter. I came across the postman-to-k6 converter, and it’s a great addition. But I’m finding a problem, mainly in the variables inside the body are not being replaced. The code looks as follows (removed great part of it to not make this too long):
// Auto-generated by the Load Impact converter
import "./libs/shim/core.js";
import "./libs/shim/expect.js";
import { group } from "k6";
export let options = { maxRedirects: 4 };
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
environment: {
baseurldevices: "http://localhost:5000/api/v1/device",
baseurlservices: "http://localhost:5000/api/v1/service",
access_token: "1eb317717b627d476f3e08fa13773270a71d1a37",
ulServiceName: "ULServicePostman",
ulEntityType: "UTest",
ulApiKey: "UL0000",
ulAttributes: '[{\n "object_id": "1",\n "name": "temp",\n "type": "string"\n },\n {\n "object_id": "2",\n "name": "humidity",\n "type": "string"\n }\n ]\n',
ulCommands: "[]",
ulStaticAttributes: "[]",
ulThingProtocol: "ul",
ulPublic: "true",
}
});
group("services", function () {
postman[Request](
{
name: "Add UL service",
id: "7a579799-67ed-4bf0-a7ab-22ebbffe825e",
method: "POST",
address: "http://" + __ENV.baseurlservices + "/add",
data:
//'{\n "name": "ulServiceName",\n "entityType": "ulEntityType",\n "thingProtocol": "ul",\n "apiKey": "ulApiKey",\n "commands": [],\n "attributes": [],\n "staticAttributes": [],\n "public": true \n}',
'{\n "name": "{{ulServiceName}}",\n "entityType": "{{ulEntityType}}",\n "thingProtocol": "{{ulThingProtocol}}",\n "apiKey": "{{ulApiKey}}",\n "commands": {{ulCommands}},\n "attributes": {{ulAttributes}},\n "staticAttributes": {{ulStaticAttributes}},\n "public": {{ulPublic}}\n}',
headers: {
"Content-Type": "application/json",
"x-nick-name": "{{access_token}}"
},
post(response) {
pm.test("Status code is 201 Created", function () {
pm.response.to.have.status(201);
});
pm.test("Response body contains the expected values", function () {
pm.expect(pm.response.text()).to.include(pm.environment.get("ulServiceName"));
pm.expect(pm.response.text()).to.include(pm.environment.get("ulEntityType"));
pm.expect(pm.response.text()).to.include(pm.environment.get("ulApiKey"));
pm.expect(pm.response.text()).to.include(pm.environment.get("ulThingProtocol"));
pm.expect(pm.response.text()).to.include(pm.environment.get("ulPublic"));
});
var service = JSON.parse(responseBody);
pm.environment.set("ul_Id", service._id);
}
})
});
The problem comes in
data:
//'{\n "name": "ulServiceName",\n "entityType": "ulEntityType",\n "thingProtocol": "ul",\n "apiKey": "ulApiKey",\n "commands": [],\n "attributes": [],\n "staticAttributes": [],\n "public": true \n}',
'{\n "name": "{{ulServiceName}}",\n "entityType": "{{ulEntityType}}",\n "thingProtocol": "{{ulThingProtocol}}",\n "apiKey": "{{ulApiKey}}",\n "commands": {{ulCommands}},\n "attributes": {{ulAttributes}},\n "staticAttributes": {{ulStaticAttributes}},\n "public": {{ulPublic}}\n}',
The different variables are not being replaced. If I use the top option (the one that is commented), it works, but for the bottom option, it says errors because it finds "{"
in the parameter.
I tried making console.log("{{ulServiceName}}")
and it prints exactly that ("{{ulServiceName}}")
instead of the value.
How can I make use of those variables? it does work inside the headers tag and the address using the same structure.
Thanks.