Home > database >  Build dynamic json payload in Jmeter using Jsr223/ beanshell pre/post processer
Build dynamic json payload in Jmeter using Jsr223/ beanshell pre/post processer

Time:05-23

                    "kits": [
                            {
                            "kitHandle": "f9d162a4-3204-4e5f-841b-c45ab60abdda",
                            "locationHandle": "5e1bbca0-19c0-480a-b8ff-66e676f5f668",
                            "containerHandle": "748f217f-6e7f-4382-897b-9c5fee5a58eb",
                            "kitID": "KitID12841790",
                            "kitUsageSeq": "585",
                            "kitStatus": "QUARANTINE",
                            "shipperID": "CONT-585"
                        
                        },
                            {
                            "kitHandle": "f9d162a4-3204-4e5f-841b-c45ab60abdda",
                            "locationHandle": "5e1bbca0-19c0-480a-b8ff-66e676f5f668",
                            "containerHandle": "748f217f-6e7f-4382-897b-9c5fee5a58eb",
                            "kitID": "KitID12841790",
                            "kitUsageSeq": "585",
                            "kitStatus": "QUARANTINE",
                            "shipperID": "CONT-585"
                        
                        }
                    ],

so in above i need the kits block to be generated 1000 times in the request, with "kithandle" and "kitID" dynamic every time.

and below is some javascript code for generating above scenario, and i want same to be impletemented in beanshell/jsr223.

CodePudding user response:

The relevant Groovy code would be something like:

def kits = []

1.upto(1000, {
    def kit = [:]
    kit.put('kitHandle', 'f9d162a4-3204-4e5f-841b-c45ab60abdda')
    kit.put('locationHandle', '5e1bbca0-19c0-480a-b8ff-66e676f5f668')
    kit.put('containerHandle', '748f217f-6e7f-4382-897b-9c5fee5a58eb')
    kit.put('kitID', 'KitID12841790')
    kit.put('kitUsageSeq', '585')
    kit.put('kitStatus', 'QUARANTINE')
    kit.put('shipperID', 'CONT-585')
    kits.add(kit)
})

def payload = [kits: kits]

vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())

the generated value can be referenced as ${payload} where required.

More information:

CodePudding user response:

Seems like your Kithandle has resemblence as UUId, so it is Handle by using function uuid -${__UUID}

  • Related