SharedArray Data Parametrization usage

Hi Team,

Below test data store in “data.json” file

    "number": 16025,
    "id": "0x1"
    "number": 16024,
    "id": "0x2"

Below is test script of reading above test data & passing in http request each time with different data

const **body** = new SharedArray('Fetch Data from JSON', ()=> {
    return JSON.parse(open('./data.json'));

export default function (){
    for (let i=0;i<body.length;i++){
    const result = http.request('GET', requestUrl,JSON.stringify(**body[i]),** params);

My question,

  1. am I using correct syntax here in all places - e.g. using for loop to iterate all test data ?
  2. If not can you please suggest what I need to correct ?

Thank You

Hi @shailendrakumaromkar

I believe the following docs can help you out:

  • Retrieving unique data showcases how you can use a SharedArray and scenario.iterationInTest or vu.idInTest to retrieve data that is unique.
  • Test lifecycke. Based on the example you shared, you might not want the same VU code to execute all the requests. Just have each iteration execute one URL, and use the above examples (retrieving unique data) to have each iteration or VU retrieve the data as needed.

It’s also worth having a look at k6-learn for an introduction to k6. Particularly examples on how to use different scenarios/executors:

I hope this helps.


Thank You @eyeveebe , I will check this out