Thanks for the clarification @Gerard
What I understand as your goal is to be able to override scenario-specific options directly from the command-line flags; rather than from the predefined options in the script.
In that regard, k6 does not allow users to do that from command-line flags. However, you should be able to achieve the same thing by using environment variables, and introducing a bit of logic in your script to use them as you wish.
k6 lets you use environment variables in the context of your test script. By using them, we should be able to achieve roughly what you’re asking for. Say you have a homepage scenario, and you wish its default VUs count to be 50
, but want to be able to change that value at runtime. You could define an environment variable, either:
- via your shell:
MY_ENV_VAR=123 k6 run myscript.js
- or by passing them using the
-e key=val
flag to the k6 command: k6 run -e my_env_var=123 script.js
You could access those values you’ve set from your script to override the options.scenarios.
of your choice.
Here is an example:
import http from "k6/http";
export const options = {
scenarios: {
products: {
executor: "constant-vus",
exec: "products",
vus: 50,
duration: "30s",
},
homepage: {
executor: "per-vu-iterations",
exec: "homepage",
vus: 50,
iterations: 100,
maxDuration: "1m",
},
},
};
if (__ENV.products_vus) {
options.scenarios.products.vus = __ENV.products_vus;
}
if (__ENV.homepage_max_duration) {
options.scenarios.homepage.maxDuration = __ENV.homepage_max_duration;
}
export function products() {
// do something
}
export function homepage() {
// do something else
}
Running this script as such: k6 run -e products_vus=12 -e homepage_max_duration=2m script.js
, or alternatively using: PRODUCTS_VUS=12 HOMEPAGE_MAX_DURATION=2m k6 run script.js
, overrides my script’s scenarios options as desired.
Let me know if that’s helpful