Hi All,
I am new to K6 and its really useful tool. I am facing a issue while running the scripts. Hope I get some help here.
- I have written postman script and its working fine, its setting the environment variables.(verified by printing in console).
- After converting from postman to k6 and running I am getting an error.
// Auto-generated by the postman-to-k6 converter
import "./libs/shim/core.js";
import "./libs/shim/urijs.js";
export let options = { maxRedirects: 4 };
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
environment: {
baseUrl:
"http://tenant-XYZ.com",
tenantId: "",
tenantName: "demo2"
}
});
export default function() {
postman[Request]({
name: "Onboard tenant",
id: "69e8633c-caa9-4d6b-bae3-2de1643564cd",
method: "POST",
address: "{{baseUrl}}/tenants",
data:
'{\r\n "name": "{{tenantName}}",\r\n "handler": "test",\r\n "description": "tenant"\r\n}',
post(response) {
//validate status
pm.test("[POST]==/Onboard tenant -- Status code is 201", () => {
pm.response.to.be.success;
});
// Set Environment variable
let responseBodyData = pm.response.json();
pm.environment.set("tenantId", responseBodyData.result._id);
}
});
}
**Error: running k6**
ERRO[0007] TypeError: Cannot read property '_id' of undefined
running at post (file:///C:/workspace/k6-notification-flow2-script.js:41:34(21))
default at executePostrequest (file:///C:/workspace/libs/shim/core.js:1253:11(22))
at executeRequest (file:///C:/workspace/libs/shim/core.js:1034:25(108))
at file:///C:/workspace/libs/shim/core.js:314:30(27)
at file:///C:/workspace/k6-notification-flow2-script.js:20:19(17) executor=per-vu-iterations scenario=default source=stacktrace
âś— [POST]==/Onboard tenant -- Status code is 201
↳ 0% — ✓ 0 / ✗ 1