0
votes

my JSON structure is:

        {
        "ID": "1",

        "DATE": "2",

        "VILLA": [{
                            "HSENO":"${HSENO}",
                            "STREETNO": "${STREETNO}",
                            "CITY": "${CITY}",
                            "STATE": "${STATE}",

                 }],
        "FLATS": []
        }

My Excel Have 1000 datas (1000 HSENO, 1000 STREETNO, 1000 CITY, 1000 STATE) for Villa's. In Jmeter how can I read these 1000 datas & make HTTP SINGLE request.

I have referred beanshell script but still couldn't succeed.

PLease help me. Thanks

1

1 Answers

1
votes
  1. Assuming that you have test.csv file in "bin" folder of your JMeter installation which looks like:

    house1,street1,city1,state1
    house2,street2,city2,state2
    house3,street3,city3,state3
    
  2. Add JSR223 PreProcessor as a child of the request you want to parameterize
  3. Put the following code into "Script" area:

    def builder = new groovy.json.JsonBuilder()
    
    @groovy.transform.Immutable
    class VILLA {
        String HSENO
        String STREETNO
        String CITY
        String STATE
    }
    
    def villas = new File("test.csv")
            .readLines()
            .collect { line ->
                new VILLA(line.split(",")[0], line.split(",")[1], line.split(",")[2], line.split(",")[3]) }
    
    builder(
            ID:1,
            DATE: 2,
            VILLA: villas.collect(),
            FLATS:[]
    )
    log.info(builder.toPrettyString())
    vars.put("payload", builder.toPrettyString())
    

You should see generated request body in jmeter.log file and should be able to use ${payload} JMeter Variable where required to pass the generated data.

enter image description here

More information: