Dynamic Scenarios in K6 is it possible?

I am new to K6 , I have query →
I have a CSV file where each row in CSV file will correspond to one testcase ,i.e. When i Iterate through CSV i will replace the data of each row in my API request and exceute the test.

Row 1 from CSV → XXX data populated in API and test executed
Row 2 from CSV-> XXX data populated in API and test executed
This is how jmeter works with CSV configurator.

My query is How can i Dynamically generate Scenarios to perform this in K6.

I tried as below →
Created Parent Script where i can loop through CSV and called Child script default function in it where in For every row i can run and verify the test.

But when i run the parentScript , output only shows 1 scenario executed as for child script default function its not considering a separate scenario.

scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0001] set up one source=console
INFO[0001] set up two source=console
INFO[0001] hiii admin source=console
INFO[0002] hiii admin source=console

Please advice how can we achieve this in K6, it similar to a DataProvider tests in testNG or CSVconfig in Jmeter.


Hi @9779012177, welcome to the community forum! :tada:

I do not understand both what you are trying to do and what isn’t working for you.

Can you provide a script example showcasing what you’ve done - you can omit any business logic and just point out where you want a line from the csv (for example).

You might also be interested in the example on how parameterize with csv and the general scenarios documentation.

Hi ,

So here is the script if you see below →

  1. parse CSV
  2. Open Request having templates which is to replaced for e.g → $username here username will be replaced with username key in CSV
  3. Scenario will loop for every row in CSV i.e. 1 row in csv holds input and out data for one testcase

Question is → Can we dynamically create scenario , such that Scenario name is the name of testcase which will be pulled from CSV ?

Some thing like below →

Loop CSV {
Create Dynamic scenario , iterate it one for every row of CSV data

SAMPLE Script - >
//CSV parsed
 const csvData = papaparse.parse(open('users.csv'), { header: true }).data;
 var request = open('./request.xml');  - //request  template opened

//scenario being iterated for all rows in CSV
 export const options = {
  scenarios: {
    'send_medication': {
      executor: 'shared-iterations',
      vus: 1,
      iterations: csvData.length,
      maxDuration: '1h',

export default function () {
	business logic  

export function handleSummary(data) {
  return {
    "summary.html": htmlReport(data),

Looking at this it seems you want to basically do the same as this example from the docs.

But replace it in xml instead of just logging the ${user}.

I have no idea what kind of template you have but you should be able to do the replace with some basic string manipulation.

Is there a particular thing that is unclear from the linked example?