【转】Jmeter-获取响应结果中参数出现的次数
在测试中,有时候会遇到要统计响应结果中某个参数出现了多少次,如果量级很大,一个一个数不太现实,下面讲一下实现自动打印出该参数出现的次数的方法。例如我的响应信息为:{"ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1","ip":"1.1.1.1",}现在请求上创建正则表达式提取器,把响应信息全部提取到变量中如下面的截图:http://images2015.cnblogs.com/blog/402802/201610/402802-20161021183229029-233373040.png然后创建一个beanshell前置处理器,脚本如下:http://common.cnblogs.com/images/copycode.gif
1 import java.util.regex.Matcher; 2 import java.util.regex.Pattern; 3 4 ip = vars.get("ip"); 5 subs = "\"ip\""; 6 Pattern pattern = Pattern.compile(subs); 7 Matcher matcher = pattern.matcher(ip); 8 int count=0; 9 while(matcher.find()){10 count++;11 }12 System.out.println(count);http://common.cnblogs.com/images/copycode.gif
执行Jmeter,控制台就打印出数值了http://images2015.cnblogs.com/blog/402802/201610/402802-20161021183750513-1861520179.png
页:
[1]