我使用 JSON 提取器从 JSON 响应中提取两个不同列表中的 2 组值
我使用 foreach 循环遍历 list1 的值,因此我可以轻松地从 list1 中一一获取值:
但我想在此 foreach 循环内的请求之一中发送 list2 中的值。 如何从 list2 中一一获取值,以便将其作为参数发送:
将为列表中的每个项目调用此 HTTP 请求。我想将 list2 中的值添加到给定 HTTP 请求中的 lastUpdated
参数。我该怎么做?
我做了一些研究,发现我们可以使用 Beanshell PreProcessor 来完成这项任务。我在 Beanshell PreProcessor 中添加了以下代码:
idx = Integer.parseInt(vars.get("item_no"))-1;
vars.put("date", vars.get("list2")[idx]);
并尝试按如下方式传递日期:
{"qId":"${q_oid}","items":[{"itemId":"${qi_id}","lastUpdated":"${date}"}]}
但是我在 lastUpdated
参数中变得空白。
注意:我已在测试计划的用户定义变量中添加了“日期”
最佳答案
list2变量保存为:list_1 list_2 list_3,...
所以改变ForEach Controller里面的变量名
vars.put("date", vars.get("list2_" + idx));
So for example when the input variable has the name inputVar, the following variables should have been defined:
inputVar_1 = wendy inputVar_2 = charles inputVar_3 = peter inputVar_4 = john
请注意,JMeter 在 ForEach Controller 中保存特殊变量:
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0
关于json - 如何在jmeter请求的请求中传递列表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51285249/