我有以下使用JSONPath
提取器
entries = ["e-1553","e-1552","c-1052","e-1551","c-1050",
"e-1550","c-1049","e-1549","c-1051","e-1548",
"c-1048","e-1547","c-1047","e-1546","c-1045",
"e-1545","e-1544","c-1046","e-1543","e-1542",
"c-1026","e-1541","e-1540","e-1539","e-1538",
"c-1025","e-1537","e-1536","c-1024","f-1535",
"f-1534"]
我想仅对那些以" e-
"开头的条目进行迭代例如" e-1553,e-1552"
等在我的ForEach控制器中排除其他条目,例如"c-1052, c-1050"
等。
这样我就可以使用http://somesite.com/e-1553等。
我该怎么做?
答案 0 :(得分:0)
鉴于你有"条目"变量,它保存JSONArray,你可以获得从" e - "开始的所有条目。如下:
将以下代码放入PostProcessor"脚本"面积:
JSONArray array = JSONArray.fromObject(vars.get("entries"));
int counter = 0;
for (int i=0;i < array.size();i++) {
String s = array.get(i).toString();
if (s.startsWith("e-"))
{
counter++;
vars.put("entry_" + counter, s);
}
}
它将产生如下变量:
entry_1=e-1553
entry_10=e-1544
entry_11=e-1543
entry_12=e-1542
entry_13=e-1541
etc.
然后添加ForEach Controller并按如下方式对其进行配置:
entry
0
current_entry
然后在HTTP请求中使用Path中的${current_entry}
。
有关JMeter中Beanshell脚本的更多信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。