简体   繁体   中英

How to send multiple JSON data from CSV file in single HTTP request in JMETER tool

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. 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.

在此处输入图像描述

More information:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM