0

I have a request payload(JSON format) which has an array with 1000 objects and each object has 6 key value pairs out of which 5 I’m reading from the csv file using parameterization and the 6th key has to be a unique date value of a future date for each of the object in the array.

I tried this with time-shift function which works for 1 iteration but I want to execute it for n- number of iterations.

I checked for groovy code for this but I have no knowledge of groovy and have started learning it.

How can I achieve this in JMeter.

Also, on reading time-shift function from HTTP Request Defaults-Parameters or from the Test Plan-User Defined Variables it does not read different date for each object, it duplicates same date of the first variable in each object.

{
  “deviceNumber": “XX”,
  “array: [
    {
      “keyValue1: “${value1_ReadFromCSV}”,
      "keyValue2”: “${value2_ReadFromCSV}”,
      "keyValue3”: “${value3_ReadFromCSV}”,
      "keyValue4”: “${value4_ReadFromCSV}”,
      "keyValue5”: “${value5_ReadFromCSV}”,
      "keyValue6”: "2020-05-23” (Should be dynamically generated)
    },
    {
      “keyValue7: “value7_ReadFromCSV”,
      "keyValue8”: "value8_ReadFromCSV",
      "keyValue9”: "value9_ReadFromCSV",
      "keyValue10”: "value10_ReadFromCSV",
      "keyValue11”: "value11_ReadFromCSV",
      "keyValue12”: "2020-05-24” (Should be dynamically generated)
    },
    .
    .
    .
    .
    {
      “keyValue995: “value995_ReadFromCSV”,
      "keyValue996”: "value996_ReadFromCSV",
      "keyValue997”: "value997_ReadFromCSV",
      "keyValue998”: "value998_ReadFromCSV",
      "keyValue999”: "value999_ReadFromCSV",
      "keyValue1000”: "2025–12-31” (Should be dynamically generated)
    }
  ]
}

I have got the partial solution to this, by reading the csv file line by line and storing each line into a variable using groovy. However, I don't want to store directly the line into the variable but to create a JSON object like above from each line of csv file with a unique future date for each object which is in the array.

The csv file is : (Note: I have removed column for date column in csv as I no longer need it.)

deviceNumber,keyValue1,keyValue2,keyValue3,keyValue4,keyValue5,keyValue7,keyValue8,keyValue9,keyValue10,keyValue11,keyValue12,keyValue13,keyValue15,keyValue15,keyValue16
01,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
02,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
03,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
.
.
.
1000,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring

Kindly suggest any reference/example to do this.

  • Can you please check https://stackoverflow.com/questions/49745549/jmeter-time-and-date-dynamic-change – Rao May 24 '20 at 03:21
  • Thanks @Rao I have gone though the link https://stackoverflow.com/questions/49745549/jmeter-time-and-date-dynamic-change earlier as well it doesn't fulfill the requirment I have for multiple iterations. Also, I did tried with timeshift function in: 1. User defined variables at test plan level and 2. Parameters in HTTP Request Defaults. – Sagar Pardeshi May 24 '20 at 03:29

1 Answers1

0

I provide only generic instructions:

  1. You can dynamically construct request body using JSR223 PreProcessor
  2. You can read CSV file into memory using File.readLines() function
  3. You can build JSON out of the values from the CSV file using JsonBuilder class

More information:

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Dmitri T
  • 159,985
  • 5
  • 83
  • 133