Brainstorming/Tips: How to run specific groups, requests and/or specific check from a single file with thousands of lines

Hi there,

so this question is similar to this: How to run only certain groups of requests

While there’s currently no way to run specific groups, which sounds like a good feature to have in k6, you can hack your way around it to use the same workaround recommended in that thread and issue for your OpenAPI generated script.

It’s not pretty, but here’s a potential workflow you could automate to transform the generated script:

# Replace all group() calls with a call to a custom mgroup() instead
sed -i 's:group(:mgroup(:g' script.js
# Append a global regex and the mgroup() function to test an environment variable for it
cat <<'EOF' >> script.js
const re = new RegExp(__ENV.K6_GROUPS ? __ENV.K6_GROUPS : '.*');
function mgroup(name, fn) {
  if (re.test(name)) {
    return group(name, fn);
  }
}
EOF

Then running the script by default will execute all groups, but you can select which ones to execute with the K6_GROUPS env var, e.g.:
K6_GROUPS='post|get' k6 run script.js.

This is far from ideal of course, but hope it helps until this is supported natively in k6. Or maybe someone else has a better suggestion :slight_smile:

1 Like