使用Jsr 223/ beanshell前/后处理器在Jmeter中构建动态json有效负载

jvidinwx  于 2022-11-09  发布在  Shell
关注(0)|答案(2)|浏览(231)
"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"

                        }
                    ],

所以在上面我需要在请求中生成1000次kits块,每次都是动态的“kithandle”和“kitID”。
下面是生成上述场景的一些javascript代码,我希望在beanshell/jsr 223中实现相同的代码。

uidvcgyl

uidvcgyl1#

相关的Groovy代码如下所示:

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())

所生成的值在需要时可以被称为${payload}
更多信息:

7hiiyaii

7hiiyaii2#

您的Kithandle似乎与UUId相似,因此使用函数uuid -${__UUID}处理

相关问题