Hi @varshagawande
We have two ways we achieve what you are looking for. This design was created for a few reason, these work well for our needs across our software portfolio.
The first way, we create individual k6 test scripts for each endpoint. We call this our endpoint definition file, those endpoints are packaged using NPM. (We do this so the test scripts could be used across our entire portfolio, different repo’s.) We don’t have any test conditions, thresholds, options in these test scripts… This is one example, with some changes to names.
/*
* @param {object} additionalReqParam
* @param {array} criteria
*/
export function getEndpoint1(additionalReqParam, criteria) {
const url = generateUrl('/svc/v1/endpoint1');
// The data must be passed as search parameters rather than the body
const urlWithParams = new URL(url);
// Add all the fields as search parameters unless null/undefined
if (criteria) {
criteria.forEach((currentCriteria) => {
const criteriaFormatted = currentCriteria.split('=');
urlWithParams.searchParams.append(
criteriaFormatted[0],
criteriaFormatted[1]
);
});
}
const headers = getHeadersWithToken(additionalReqParam.token);
const resp = execRequest('GET', urlWithParams.toString(), null, headers);
return resp;
}
As those test scripts are developed, they can put put into the Test Scenario script that would have something like this. Again, removed some information and condensed. When we run this scenario test script, each of the groups will have their own metrics. We also set thresholds for each of these groups.
export default function () {
// Optional wait timer to start all VUs in proper order
preIteration();
let token;
group('get some endpoint1 type', function () {
// Make the request to the endpoint
getEndpoint1(requestParams);
});
group('get some endpoint2 type', function () {
// Make the request to the endpoint
getEndpoint2(requestParams, criteria);
});
The other design we have has three components. I can’t say if this is the most performant but the collection is pretty small. There is the test script, a json data file and the test scenario.
The test script is universal, some may say a wrapper of sort. It reads the json file for each of the defined API’s and constant parameters, build that into an npm package. The Scenario test script is setup like the above, and just consumes the npm module for the test.
In either method the need you have is met.
Good Luck!
-Misty