在测试中,有时候会遇到要统计响应结果中某个参数出现了多少次,如果量级很大,一个一个数不太现实,下面讲一下实现自动打印出该参数出现的次数的方法。
例如我的响应信息为:{"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",}
现在请求上创建正则表达式提取器,把响应信息全部提取到变量中如下面的截图:
然后创建一个beanshell前置处理器,脚本如下:
import java.util.regex.Matcher; import java.util.regex.Pattern; ip = vars.get("ip"); subs = "\"ip\""; Pattern pattern = Pattern.compile(subs); Matcher matcher = pattern.matcher(ip); int count=0; while(matcher.find()){ count++; } System.out.println(count);
执行Jmeter,控制台就打印出数值了
原文地址:https://www.cnblogs.com/111testing/p/10391940.html
时间: 2024-10-04 02:06:45