JMeter的。从beanshell预处理器获取当前的HTTP sampler正文数据

时间:2014-10-14 07:54:06

标签: jmeter load-testing

在HTTP Sampler中发送查询之前,我需要在beanshell预处理器中对此查询进行一些更改。那么,问题是如何从beanshell预处理器访问当前的采样器主体数据?我可以获取Name,Path,IP等(例如sampler.getPropertyAsString(" HTTPSampler.domain"))但不知道如何获取正文数据。

2 个答案:

答案 0 :(得分:9)

请在下面找到答案(假设我们正在谈论HTTP Request

  • 姓名:sampler.getName()
  • IP:sampler.getUrl().getHost()
  • 路径:sampler.getUrl().getPath()
  • 如果您需要请求参数:

    Arguments arguments = sampler.getArguments();
    for (int i=0;i<arguments.getArgumentCount();i++)
    {
        Argument argument = arguments.getArgument(i);
        String name = argument.getName();
        String value = argument.getValue();
        // do what you need
    }
    

如果您需要更多信息,请参阅HTTPSamplerProxy JavaDoc

如果不是HTTP请求,您可以找出此sampler变量所指的类

log.info(sampler.getClass().getName());

从jmeter.log文件中找出类名,然后查找JavaDoc

有关Beanshell脚本编制的更多信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。

答案 1 :(得分:2)

感谢 @Dmitri T

我得到了 13:28:13 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.Header; sampler.getHeaderManag . . . '' : Typed variable declaration : Class: Arguments not found in namespace  使用

时出错
Arguments arguments = sampler.getArguments();
for (int i=0;i<arguments.getArgumentCount();i++)
{
    Argument argument = arguments.getArgument(i);
    String name = argument.getName();
    String value = argument.getValue();
    // do what you need
}

导入后 import org.apache.jmeter.config.Argument; import org.apache.jmeter.config.Arguments;

我解决了这个问题