gpt4 book ai didi

java - 如何在 Jmeter 中从 json 文件准备多行

转载 作者:行者123 更新时间:2023-12-01 18:19:03 24 4
gpt4 key购买 nike

我是 Jmeter 的新手,我正在 json 文件中生成随机数据(例如 n 个请求)。

这些是 json 文件中的请求{"firstName":"Colton","lastName":"Alvarez","password":"K42mC7UQ","email":"Robert2@test.COM","orgName":"Alist","locationName ":"史迪威大道","address1":"史迪威大道","address2":"11史迪威大道","city":"旧金山","state":"南达科他州","country":"美国","zipCode":"12901","orgEmail":"Gavin@test.COM"}

{"firstName":"Stella","lastName":"Barrera","password":"BUiVwvAw","email":"Alex3@test.COM","orgName":"快速咨询","locationName":"科夫巷","address1":"科夫巷","address2":"8科夫巷","city":"迈阿密","state":"北卡罗来纳州","country": "美国","zipCode":"26257","orgEmail":"Anthony@test.COM"}

{"firstName":"Violet","lastName":"Trujillo","password":"O5belqdN","email":"London1@test.COM","orgName":"Buapel Limited ","locationName":"福特街","address1":"福特街","address2":"21福特街","city":"迈阿密","state":"加利福尼亚州","country":"美国","zipCode":"72159","orgEmail":"Thomas@test.COM"}

{"firstName":"Aubrey","lastName":"Tyler","password":"Qj32XyDE","email":"Julian4@test.COM","orgName":"Yrsa Associates ","locationName":"夏日广场","address1":"夏日广场","address2":"9夏日​​广场","city":"纽约","state":"马里兰州","country": "美国","zipCode":"19250","orgEmail":"Cooper@test.COM"}

{"firstName":"Emily","lastName":"Gilliam","password":"TNKqqqfX","email":"London5@test.COM","orgName":"Alist","locationName":"华盛顿步行街","address1":"华盛顿步行街","address2":"19华盛顿步行街","city":"纽约","state":"马萨诸塞州","country":"美国","zipCode":"90694","orgEmail":"Tristan@test.COM"}

现在我希望 jmeter 将此数据作为请求正文来命中 n 个线程

问题是,当我将单个请求的数据放入 json 文件时,它会读取它并让我成功。但是当多行数据放入 json 中时,它会尝试在请求中获取整个数据。 picking file in jmeter但是我希望 jmeter 对于每个不一样的请求从 json 中一一挑选数据。

最佳答案

很可能是因为__FileToString() function整个文件读取到请求正文中,如果文件中的新行上有单独的 JSON 正文负载,您可能需要使用 __StringFromFile() function相反,每次调用时都会从给定文件中读取下一行。

此外,如果数据确实是“随机”的,您甚至可以继续使用单个测试数据“占位符”,例如将其更改为如下所示:

{
"firstName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(6),)}",
"lastName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10),)}",
"password": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(8),)}",
"email": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(6),)}@test.COM",
"orgName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(6),)}",
"locationName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(20),)}",
"address1": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(20),)}",
"address2": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(20),)}",
"city": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10),)}",
"state": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10),)}",
"country": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(8),)}",
"zipCode": "${__groovy(orgorg.apache.commons.lang3.RandomStringUtils.randomNumeric(5),)}",
"orgEmail": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(6),)}@test.COM"
}

wrap your __FileToString() function into __eval() function像:

${__eval(${__FileToString(test.json,,)})}

这样您就可以在每个请求上获得随机值

关于java - 如何在 Jmeter 中从 json 文件准备多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60314214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com