我有一个请求有效负载(JSON格式),它有一个包含1000个对象的数组,每个对象有6个键值对,其中5个键值对是我使用参数化从csv文件中阅读的,第6个键值必须是数组中每个对象未来日期的唯一日期值。
我尝试了这个与时移功能,为1迭代工作,但我想执行它的n-迭代次数。
我为此检查了Groovy代码,但我对Groovy一无所知,我已经开始学习它了。
如何在JMeter中实现这一点?
此外,在从HTTP请求默认值-参数或测试计划-用户定义变量阅读时移函数时,它不会读取每个对象的不同日期,而是复制每个对象中第一个变量的相同日期。
{
“deviceNumber": “XX”,
“array: [
{
“keyValue1: “${value1_ReadFromCSV}”,
"keyValue2”: “${value2_ReadFromCSV}”,
"keyValue3”: “${value3_ReadFromCSV}”,
"keyValue4”: “${value4_ReadFromCSV}”,
"keyValue5”: “${value5_ReadFromCSV}”,
"keyValue6”: "2020-05-23” (Should be dynamically generated)
},
{
“keyValue7: “value7_ReadFromCSV”,
"keyValue8”: "value8_ReadFromCSV",
"keyValue9”: "value9_ReadFromCSV",
"keyValue10”: "value10_ReadFromCSV",
"keyValue11”: "value11_ReadFromCSV",
"keyValue12”: "2020-05-24” (Should be dynamically generated)
},
.
.
.
.
{
“keyValue995: “value995_ReadFromCSV”,
"keyValue996”: "value996_ReadFromCSV",
"keyValue997”: "value997_ReadFromCSV",
"keyValue998”: "value998_ReadFromCSV",
"keyValue999”: "value999_ReadFromCSV",
"keyValue1000”: "2025–12-31” (Should be dynamically generated)
}
]
}
通过逐行阅读csv文件并使用groovy将每一行存储到一个变量中,我已经得到了部分解决方案。但是,我不想直接将行存储到变量中,而是从csv文件的每一行创建一个JSON对象,为数组中的每个对象创建一个唯一的未来日期。
csv文件为:(注:我已经删除了csv中的日期列,因为我不再需要它。
deviceNumber,keyValue1,keyValue2,keyValue3,keyValue4,keyValue5,keyValue7,keyValue8,keyValue9,keyValue10,keyValue11,keyValue12,keyValue13,keyValue15,keyValue15,keyValue16
01,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
02,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
03,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
.
.
.
1000,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring,somestring
请提出任何参考/例子来做到这一点。
1条答案
按热度按时间oxcyiej71#
我只提供一般说明:
1.可以使用JSR223预处理器动态构造请求正文
1.您可以使用File. readLines()函数将CSV文件读入内存
1.您可以使用JsonBuilder类根据CSV文件中的值构建JSON
更多信息: