When I include tagWithCurrentStageIndex();
or tagWithCurrentStageProfile();
in my script, I get a TypeError: Value is not an object: undefined
for that line. What am I doing wrong?
Here’s the entire script:
import http from "k6/http";
import { check, sleep } from "k6";
import {
uuidv4,
tagWithCurrentStageIndex,
tagWithCurrentStageProfile,
} from "https://jslib.k6.io/k6-utils/1.2.0/index.js";
export const options = {
stages: [
{ duration: "30s", target: 25 },
{ duration: "15m", target: 25 },
{ duration: "30s", target: 50 },
{ duration: "15m", target: 50 },
{ duration: "30s", target: 75 },
{ duration: "15m", target: 75 },
{ duration: "30s", target: 100 },
{ duration: "15m", target: 100 },
{ duration: "30s", target: 125 },
{ duration: "15m", target: 125 },
{ duration: "30s", target: 150 },
{ duration: "15m", target: 150 },
{ duration: "30s", target: 175 },
{ duration: "15m", target: 175 },
{ duration: "30s", target: 200 },
{ duration: "15m", target: 200 },
],
thresholds: {
http_req_duration: ["p(99) < 1000", "p(95) < 700"], // 99% of requests must complete below 1s, 95% below 0.7s
http_req_failed: ["rate<0.01"], // http errors should be less than 1%
},
};
const API_BASE_URL = "http://<FQDN>:3000";
// variable depending on target environment
const ACCESS_TOKEN = "<token>";
export default () => {
tagWithCurrentStageIndex();
tagWithCurrentStageProfile();
const authHeaders = {
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
"Content-Type": "application/json",
Accept: "application/json",
},
};
const TIMESTAMP = uuidv4();
const DOCTITLE = `Smoke-Test-Complex-1-${TIMESTAMP}`;
var passed;
// go to Documents
const resp_getDocVersions = http.get(
`${API_BASE_URL}/api/v1/documentVersions?st=DRAFT&pn=1&ps=5&oc=ACTIVITY&dr=DESC`,
authHeaders
);
//console.log("resp_getDocVersions", resp_getDocVersions);
passed = check(resp_getDocVersions, {
"is 200 OK": (r) => r.status === 200,
});
if (!passed) {
console.error("resp_getDocVersions", resp_getDocVersions);
}
sleep(1);
// search for DOCTITLE
const resp_getDocVersions_src = http.get(
`${API_BASE_URL}/api/v1/documentVersions?st=DRAFT&pn=1&ps=5&sr=${DOCTITLE}&oc=ACTIVITY&dr=DESC`,
authHeaders
);
//console.log("resp_getDocVersions_src", resp_getDocVersions_src);
passed = check(resp_getDocVersions_src, {
"is 200 OK": (r) => r.status === 200,
});
if (!passed) {
console.error("resp_getDocVersions_src", resp_getDocVersions_src);
}
sleep(1);
// create New Document
const payload_postDocuments = {
data: {
id: "",
organization: {
id: ORG_ID,
},
docType: "DOCUMENT",
members: [
{
userId: USER_ID,
role: "OWNER",
},
],
version: {
id: "",
title: DOCTITLE,
governanceModel: GOVMD,
tags: ["complex", "smoke", "test"],
docCategories: DOCCATS,
docCredits: [],
state: "DRAFT",
createdAt: "Fri Jul 22 2022 10:19:39 GMT-0400 (Eastern Daylight Time)",
lastModified:
"Fri Jul 22 2022 10:19:39 GMT-0400 (Eastern Daylight Time)",
pages: {},
documentVersionAudiences: {},
topic_subtopic_pairs: [
{
topic: "test",
subtopic: "complex test",
},
],
},
},
};
const resp_postDocuments = http.post(
`${API_BASE_URL}/api/v1/documents`,
JSON.stringify(payload_postDocuments),
authHeaders
);
//console.log("resp_postDocuments", resp_postDocuments);
passed = check(resp_postDocuments, {
"is 201 Created": (r) => r.status === 201,
});
if (!passed) {
console.error("resp_postDocuments", resp_postDocuments);
}
sleep(1);
if (
resp_postDocuments.status === 201 &&
resp_postDocuments.json() &&
resp_postDocuments.json().data &&
resp_postDocuments.json().data.version &&
resp_postDocuments.json().data.version.id
) {
const docVersionId = resp_postDocuments.json().data.version.id;
// add a guide
let payload_postDocVersionPage = {
data: {
isGuide: true,
isRoot: false,
title: "Clinical notes",
persona: PERSONA,
careCategory: CARECAT,
patientGroup: PATGROUP,
content: {
order: 0,
pageType: "guide",
content: LOREMIPSUMDIV,
tooltip: "",
},
},
};
const resp_postDocVersionPage = http.post(
`${API_BASE_URL}/api/v1/documentVersions/${docVersionId}/pages`,
JSON.stringify(payload_postDocVersionPage),
authHeaders
);
//console.log("resp_postDocVersionPage", resp_postDocVersionPage);
passed = check(resp_postDocVersionPage, {
"is 201 Created": (r) => r.status === 201,
});
if (!passed) {
console.error("resp_postDocVersionPage", resp_postDocVersionPage);
}
sleep(1);
// delete the docversion
const resp_deleteDocVersion = http.del(
`${API_BASE_URL}/api/v1/documentVersions/${docVersionId}`,
null,
authHeaders
);
//console.log("resp_deleteDocVersion", resp_deleteDocVersion);
passed = check(resp_deleteDocVersion, {
"is 204 No Content": (r) => r.status === 204,
});
if (!passed) {
console.error("resp_deleteDocVersion", resp_deleteDocVersion);
}
sleep(1);
}
};
const LOREMIPSUM =
"Lorem ipsum dolor sit amet.";
const LOREMIPSUMDIV = `<div>${LOREMIPSUM.split("\n").join("<br />")}</div>`;