json - 如何在jmeter请求的请求中传递列表中的值

标签 json jmeter

我使用 JSON 提取器从 JSON 响应中提取两个不同列表中的 2 组值

Extractor1

enter image description here

我使用 foreach 循环遍历 list1 的值,因此我可以轻松地从 list1 中一一获取值:

enter image description here

但我想在此 foreach 循环内的请求之一中发送 list2 中的值。 如何从 list2 中一一获取值,以便将其作为参数发送:

enter image description here

将为列表中的每个项目调用此 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/

相关文章:

jmeter - 总体事件线程图中的线程数差异

web-services - 如何在 jmeter 中为 SOAP 请求添加正确的签名

javascript - 原型(prototype)上的 Object.defineProperty 阻止 JSON.stringify 序列化它

testing - Jmeter:迭代并递增每个请求然后返回

git - Jmeter 和 Bitbucket 服务器负载测试

regex - 匹配任何 URL 参数值的正则表达式(Perl 语法)

python - 在 Python 中格式化 JSON

javascript - 如何使用主机提供的速率限制来限制我的 JS API 获取请求?

python - 解析 JIRA webhook 注释

ruby-on-rails - Rails 3.2.3 和 json 中的 Flash 消息