计数jmeter中的重定向 [英] Count redirects in jmeter

查看:187
本文介绍了计数jmeter中的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我使用了 HTTP请求启用了跟踪重定向" 的采样器,并希望保持这种状态.作为断言的第二项检查,我也想计算重定向的数量,但是我不想实现

At the moment im usig HTTP request sampler with 'Follow Redirects' enabled and want to keep it that way. As a secondary check besides assertion i want to count the number of redirects as well, but i dont want to implement this solution.

当我只能使用1个HTTP采样器和一个后处理器(现在为beanshell)并获取此信息时,有没有办法?我正在检查 SamplerResult文档,但找不到任何方法可以为我提供这些信息.

Is there a way when i can use only 1 HTTP sampler and a postprocessor (beanshell for now) and fetch this information? Im checking SamplerResult documentation , but cant find any method which would give back this information for me.

推荐答案

我听说了 Groovy是新的黑色,而且鼓励用户使用JSR223测试元素和__groovy ()自JMeter 3.1 开始作为Beanshell发挥作用,因此您可以按如下方式对重定向进行计数:

I heard Groovy is new black moreover users are encouraged to use JSR223 Test Elements and __groovy() function since JMeter 3.1 as Beanshell performs not that well so you can count the redirects as follows:

  1. JSR223 PostProcessor 添加为HTTP请求采样器的子代
  2. 将以下代码放入脚本"区域:

  1. Add JSR223 PostProcessor as a child of your HTTP Request sampler
  2. Put the following code into "Script" area:

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)

运行测试后,您将能够在 jmeter.log 文件中看到发生的重定向次数:

Once you run your test you will be able to see the number of occurred redirects in jmeter.log file:

这篇关于计数jmeter中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆