Parameterize http call per VU

I have a simple call like this:

get('https://xxx/xxx/xxx/proxy/login?test_pid=05085600143')

For every VU in my K6 test I would like to use a pid from my csv file instead of the hardcoded value 05085600143.

I have imported my file at the start of my script like this:

const csvDataPatients = new SharedArray('patients', function () {return papaparse.parse(open('../testdata/patients.csv'), { header: true }).data;});

The csv file looks like this:

fnr
05085600143,
05085600144,
05085600145

In i.e. Gatling/Scala I can use it like this:

.exec GET ('https://xxx/xxx/xxx/proxy/login?test_pid=${fnr}')

Is there a similar way to do this in K6?

Hi @fugmag !

For sure, it’s possible :relaxed:

You just need to find the proper mapping of the csvDataPatients to the VU. Let’s say you have a 1:1 match, another words number of records in your CSV file is the same as the number of virtual users in your test (or less). Then you can use the __VU constant, and it could look something like http.get('https://xxx/xxx/xxx/proxy/login?test_pid=' + csvDataPatients[__VUU])

Let me know if that answers,
Cheers!

Hi, that worked perfect!. Thanks @olegbespalov

1 Like