Execution of new scenarios from CLI

You can’t specify that directly as a CLI argument, sorry, though you can do it with a bit of extra coding and k6 environment variables. Something like this:

const possibleScenarios = {
    bookmarks: {
        executor: 'constant-vus',
        exec: 'bookmarks',
        vus: 2,
        duration: '10s',
    },
    tags: {
        executor: 'per-vu-iterations',
        exec: 'tags',
        vus: 2,
        iterations: 10,
        startTime: '30s',
        maxDuration: '1m',
    },
};

let enabledScenarios = {};

__ENV.SCENARIOS.split(',').forEach(scenario => enabledScenarios[scenario] = possibleScenarios[scenario]);

export let options = {
    discardResponseBodies: true,
    scenarios: enabledScenarios,
};

export function bookmarks() {
}

export function tags() {
}

Then, you can run this script with:

k6 run --env SCENARIOS=bookmarks,tags script.js
k6 run --env SCENARIOS=tags script.js
k6 run --env SCENARIOS=bookmarks script.js

And, while you’d probably want some better error detection, this should be serviceable for any number of scenarios.

3 Likes