Redirect 在jmeter中计数重定向
目前,我正在使用启用了“跟随重定向”的HTTP请求采样器,并希望保持这种状态。除了断言之外,作为辅助检查,我还想计算重定向的数量,但我不想实现解决方案 当我只能使用1个HTTP采样器和一个后处理器(现在是beanshell)来获取这些信息时,有没有办法?我正在检查,但找不到任何方法可以为我返回此信息。将以下内容添加为您的取样器的子项:Redirect 在jmeter中计数重定向,redirect,jmeter,Redirect,Jmeter,目前,我正在使用启用了“跟随重定向”的HTTP请求采样器,并希望保持这种状态。除了断言之外,作为辅助检查,我还想计算重定向的数量,但我不想实现解决方案 当我只能使用1个HTTP采样器和一个后处理器(现在是beanshell)来获取这些信息时,有没有办法?我正在检查,但找不到任何方法可以为我返回此信息。将以下内容添加为您的取样器的子项: 适用于:主样本和子样本 要检查的字段:响应代码 正则表达式:(\d+) 模板:$1$ 匹配号:-1 然后添加BeanShell后处理器作为采样器的子级,并将以
- 适用于:主样本和子样本
- 要检查的字段:响应代码
- 正则表达式:(\d+)
- 模板:$1$
- 匹配号:-1
int matchNr = Integer.parseInt(vars.get("MyVar_matchNr"));// MyVar is the name of the variable of the above regular expression extractor
int counter = 0;
for(i=1; i <= matchNr; i++){
String x = vars.get("MyVar_"+i);
if(x.equals("302")){
counter = counter + 1;
}}
log.info(Label + ": Number of redirects = " + String.valueOf(counter));// The output will be printed in the log like this(BeanShell PostProcessor: Number of redirects = 3 ) so you might want to change the name of the beanshell post processor to the same name of your sampler.
int redirects = 0;
def range = new IntRange(false, 299, 400)
prev.getSubResults().each {
if (range.contains(it.getResponseCode() as int)) {
redirects++;
}
}
log.info('Redirects: ' + redirects)
int matchNr=Integer.parseInt(vars.get(“MyVar_matchNr”);//MyVar是上述正则表达式提取器的变量的名称
int计数器=0;
对于(i=1;i添加以下内容作为采样器的子项:
- 适用于:主样本和子样本
- 要检查的字段:响应代码
- 正则表达式:(\d+)
- 模板:$1$
- 匹配号:-1
然后添加BeanShell后处理器作为采样器的子级,并将以下内容添加到脚本区域:
int matchNr = Integer.parseInt(vars.get("MyVar_matchNr"));// MyVar is the name of the variable of the above regular expression extractor
int counter = 0;
for(i=1; i <= matchNr; i++){
String x = vars.get("MyVar_"+i);
if(x.equals("302")){
counter = counter + 1;
}}
log.info(Label + ": Number of redirects = " + String.valueOf(counter));// The output will be printed in the log like this(BeanShell PostProcessor: Number of redirects = 3 ) so you might want to change the name of the beanshell post processor to the same name of your sampler.
int redirects = 0;
def range = new IntRange(false, 299, 400)
prev.getSubResults().each {
if (range.contains(it.getResponseCode() as int)) {
redirects++;
}
}
log.info('Redirects: ' + redirects)
int-matchNr=Integer.parseInt(vars.get(“MyVar_-matchNr”);//MyVar是上述正则表达式提取器的变量名
int计数器=0;
对于(i=1;i我还听说Beanshell的表现不是很好,因此您可以按如下方式计算重定向:
添加为HTTP请求采样器的子级
将以下代码放入“脚本”区域:
运行测试后,您将能够在jmeter.log文件中看到发生的重定向数:
此外,我听说Beanshell的性能不太好,因此您可以按如下方式计算重定向:
添加为HTTP请求采样器的子级
将以下代码放入“脚本”区域:
运行测试后,您将能够在jmeter.log文件中看到发生的重定向数:
是否只对一个采样器的重定向进行计数?对每个采样器分别进行计数。是否只对一个采样器的重定向进行计数?对每个采样器分别进行计数。