1

I have One POST request and below is the My Body Payload .

{
    "ABC": "ITBK1",
    "Code": "AH01001187",
    "ScheduleDate": "2021-09-02T22:59:00Z",
    "FilterType": 2,
    "FilterData": [
        "LoadTest92","LoadTest93"
    ]
}

I'm passing the ContractorId to filterData as below.

{
    "ABC": "ITBK1",
    "Code": "AH01001187",
    "ScheduleDate": "${startTo}",
    "FilterType": 2,
    "FilterData": ["${contractorId}"]
}

but it taking one id at a time for this Json. How can i send multiple data for this FilterData jsonArray from csv please help on this.

1 Answers1

2

First of all don't post code (including CSV file content) as image

As per CSV Data Set Config documentation:

By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

So it means that you need to go to the next iteration in order to read the next line.

If you want to send all the values from column J as the "FilterData" you could do something like:

  1. Add JSR223 PreProcessor as a child of the request you want to parameterize

  2. Put the following code into "Script" area:

    def lines = new File('/path/to/your/file.csv').readLines()
    
    def payload = []
    
    lines.each { line ->
        def contractor = line.split(',')[9]
        payload.add(contractor as String)
    }
    
    vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())
    
  3. That's it, use ${payload} instead of your ["${contractorId}"] variable in the HTTP request.

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks a lot Dmitri, but i'm getting filterData in below format "FilterData": [ "[abc]","[Jagan1]","[Jagan2]","[Jagan3]","[Jagan4]"] but required format is "FilterData": [ "abc","Jagan1","Jagan2","Jagan3","Jagan4"] How can escape this brackets – Jagannatha Mv Sep 03 '21 at 06:00
  • Hi @Dmitri any solution ? – Jagannatha Mv Sep 03 '21 at 08:36
  • You have the solution, depending on what is in your CSV file you might need to adapt it a little bit, unfortunately I'm not telepathic enough to tell what exactly needs to be done without seeing the file itself. – Dmitri T Sep 03 '21 at 10:21
  • @JagannathaMv : Were you able to resolve this, as i am also getting the same issue where in within list each element is within double quotes & braces – user1416932 Sep 30 '22 at 15:10