在測(cè)試中蜗元,有時(shí)候會(huì)遇到要統(tǒng)計(jì)響應(yīng)結(jié)果中某個(gè)參數(shù)出現(xiàn)了多少次系冗,如果量級(jí)很大,一個(gè)一個(gè)數(shù)不太現(xiàn)實(shí)掌敬,下面講一下實(shí)現(xiàn)自動(dòng)打印出該參數(shù)出現(xiàn)的次數(shù)的方法。
例如我的響應(yīng)信息為:
{"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",}
現(xiàn)在請(qǐng)求上創(chuàng)建正則表達(dá)式提取器楷兽,把響應(yīng)信息全部提取到變量中如下面的截圖:
然后創(chuàng)建一個(gè)beanshell前置處理器华临,腳本如下:
1 importjava.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);
執(zhí)行Jmeter,控制臺(tái)就打印出數(shù)值了