1

I asked a question yesterday about creating a dynamic request body with pre-processors on JMeter. Thanks to Dmitri T, I almost got what I wanted.

Old question here: JMeter Creating a Pre-Processor that will generate a request body based on a user defined variable


But right now, I cannot get dynamic values from my CSV file into the request body.

MY CSV File Example Data:

Reading CSV successfully finished, 20 records found:
${id} = 1000011
${email} = a1000011@smartmessage.com
------------
${id} = 1000012
${email} = a1000012@smartmessage.com
------------
${id} = 1000013
${email} = a1000013@smartmessage.com

My Pre-Processor that generates request body:

    import groovy.json.JsonBuilder;
    
    def payload = [:]
    def X = 10 // read user input here somehow
    
    payload.put('message_job_id', '28b0a005-9ef1-475c-b33c-ade900f19e4c')
    payload.put('campaign_group', 'Entegrasyon')
    payload.put('template_id', 'cf585c8c-c675-40d2-b88a-ade900c898d5')
    
    def recipient_list = []
    1.upto(X, { x ->
        def recipient = [:]
        recipient.put('customer_id', vars.get('id') + x)
        def target = [:]
        def address = ['address': vars.get('email' + x)]
        target.put('target', address)
        recipient.put('target', target)
        recipient_list.add(recipient)
    })
    
    payload.put('recipient_list', recipient_list)
    
    
    vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())

My Generated Request Body in View Results Tree:

  {
        "message_job_id": "28b0a005-9ef1-475c-b33c-ade900f19e4c",
        "campaign_group": "Entegrasyon",
        "template_id": "cf585c8c-c675-40d2-b88a-ade900c898d5",
        "recipient_list": [
            {
                "customer_id": "10000111",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000112",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000113",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000114",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000115",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000116",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000117",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000118",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "10000119",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            },
            {
                "customer_id": "100001110",
                "target": {
                    "target": {
                        "address": null
                    }
                }
            }
        ]
    }

As you can see, address key has always null values, but I want to fill this key with email variables in CSV file.

Gökhan Uçar
  • 191
  • 15

1 Answers1

0

If you need to build a request body from CSV file and send data from multiple lines in "one shot" - you won't be able to achieve this using CSV Data Set Config and derivatives because CSV Data Set Config reads next line for each iteration of the each user.

If you need to read multiple lines within the bounds of a single iteration - you will either need to switch to __CSVRead() function or read the data from the CSV file directly in Groovy.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133