如何通过JMeter从html页面提取所有reg表达式匹配项 [英] How to extract All of reg expression matches from html page via JMeter
问题描述
我有一个html页面,其中包含学生的userIds.我需要从该html页面中提取所有userId值,并将其用于JMeter HTTP请求的参数中.
例如,我在htm页面上有以下数据.
<input type="checkbox" StudentID="1503"
<input type="checkbox" StudentID="1504"
<input type="checkbox" StudentID="1505"
等等.
我需要发送的参数值是这样的 selectedIds = 1503,1504,1505等等.
现在,我不确定如何获得第二个请求中发送的结果.我可以提取&一次使用一个值,但无法弄清楚如何获取值,就像我要求"1503,1504,1505 ..."
目前我的Reg Exp提取器就是这样
参考名称:myTestVar Reg表达式:StudentID =(.+?)" 模板:$ 1 $ 匹配编号:-1
在我的第二个请求中,我引用了变量$ {myTestVar}
请指导我需要做些什么才能以期望的方式获得结果..
"1504,1505,1506"
您可以使用BeanShell后处理器:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String response = prev.getResponseDataAsString();
String finalArr = "";
Pattern pattern = Pattern.compile("<input type=\"checkbox\" StudentID=\"(\\d+?)\"");
Matcher matcher = pattern.matcher(response);
while (matcher.find())
{
finalArr = finalArr + matcher.group(1) + ",";
}
或者,如果您使用的是Regex Extractor,那么也可以在Beanshell后处理器中使用
:Integer N = Integer.valueOf(vars.get("myTestVar _matchNr"));
String finalArr = "";
for(Integer i = 1; i <= N; i++)
{
finalArr = finalArr + (vars.get("myTestVar "+String.valueOf(i)+"_g1")) + ",";
}
I have a html page containing userIds of students. I need to extract all the userId values from this html page and use them in a parameter of JMeter HTTP request..
For example i have following data on htm page.
<input type="checkbox" StudentID="1503"
<input type="checkbox" StudentID="1504"
<input type="checkbox" StudentID="1505"
so on..
The value I need to send in parameter is like this selectedIds= 1503,1504,1505 and so on..
Now I am not sure how I can get the result that i need to send in my second request. I can extract & use one value at a time but could not figure out how to get values like I require "1503,1504,1505..."
Currently my Reg Exp extractor is like this
Reference Name: myTestVar Reg Expression: StudentID="(.+?)" Template: $1$ MatchNo: -1
In my second request I am referencing to variable ${myTestVar}
Please guide what else I need to do to get the results in desired way..
"1504,1505,1506"
You can use BeanShell Postprocessor:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String response = prev.getResponseDataAsString();
String finalArr = "";
Pattern pattern = Pattern.compile("<input type=\"checkbox\" StudentID=\"(\\d+?)\"");
Matcher matcher = pattern.matcher(response);
while (matcher.find())
{
finalArr = finalArr + matcher.group(1) + ",";
}
Or if you are using Regex Extractor then also in Beanshell Postprocessor:
Integer N = Integer.valueOf(vars.get("myTestVar _matchNr"));
String finalArr = "";
for(Integer i = 1; i <= N; i++)
{
finalArr = finalArr + (vars.get("myTestVar "+String.valueOf(i)+"_g1")) + ",";
}
这篇关于如何通过JMeter从html页面提取所有reg表达式匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!