如何在Jmeter汇总报告的标签中包含参数

how to include parameters in label of Jmeter summary report

我可以在 jmeter 中成功创建摘要报告,但在标签列中我需要完整的获取请求以及参数 passed.I 我没有获取 url 中传递的参数。

您可以在 Beanshell 脚本的帮助下自动填充它。

示例:

  1. 添加 Beanshell PostProcessor 作为 HTTP 请求
  2. 的子项
  3. 将以下代码放入后处理器的 "Script" 区域:

    import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
    import org.apache.jmeter.config.Arguments;
    import org.apache.jmeter.testelement.property.PropertyIterator;
    import org.apache.jmeter.testelement.property.JMeterProperty;
    
    HTTPSamplerProxy sampler = (HTTPSamplerProxy) ctx.getCurrentSampler();
    StringBuilder builder = new StringBuilder();
    builder.append(sampler.getUrl());
    Arguments args = sampler.getArguments();
    
    PropertyIterator iter = args.iterator();
    
    while (iter.hasNext()) {        
          builder.append (iter.next().getStringValue());          
    }
    
    prev.setSampleLabel(builder.toString());
    
  4. 运行你的测试。

代码获取 URL 和所有参数及其值,并使用这些值更新父采样器名称:

如你所见,HTTP Request变成了http://example.com/foo=bar

您可以将后处理器放置在与 HTTP 请求采样器相同的级别,以避免多次复制粘贴它或使用 Beanshell Listener or Beanshell Assertion 代替。

请参阅 How to use BeanShell: JMeter's favorite built-in component 指南,了解有关在 JMeter 中使用脚本的综合信息,并了解所有这些内容(如 ctxprev 的含义)。