Search code examples
k6

k6 custom parameter on run line


How can I add a --testenv test12 custom parameter to my tests:

k6 --out cvs=results.csv run --vus 60 --duration 2m --testenv test12 ./mass-login.js

In k6s default function the variable is defined:

export default function () {
  :  
  //const testenvs = ['test12', 'test1', 'test4', 'qa-04', 'prod'];
  const testenvs = ['qa-04'];

Current hack is to have different js files, except for 1 line fully redundant.


Solution

  • You can set an environment variable:

    k6 -e testenv=test12 ./your_script.js
    

    … and then read it in your test:

    const testenv = __ENV.testenv;