Jmeter 前置处理器 BeanShell_PreProcessor 适用思考


首先摘抄一段官方文档的话:

Before invoking the script, some variables are set up in the BeanShell interpreter:

  • log - (Logger) - can be used to write to the log file
  • ctx - (JMeterContext) - gives access to the context
  • vars - (JMeterVariables) - gives read/write access to variables:
    vars.get(key);
    vars.put(key,val);
    vars.putObject("OBJ1",new Object());
  • props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
  • prev - (SampleResult) - gives access to the previous SampleResult (if any)
  • sampler - (Sampler)- gives access to the current sampler

For details of all the methods available on each of the above variables, please check the Javadoc



根据官方文档可以看到, jmeter的beanshell前置处理器有一些内置的变量

log 对应的对象是Logger


ctx 对应的对象是JMeterContext  

vars对应的对象是 JMeterVariables

props对应的对象是class java.util.Properties

prev对应的对象是SampleResult,但是需要注意他是获取前一次请求的SampleResult

sampler对应的对象是Sampler, 需要注意的是Sampler取样器是jmeter中各种各样取样器的父类, 如果这个请求时http请求, 那么                     sampler就是HttpSampler

有了几个内置的参数,基本上可以可以对jmeter进行完整的控制, 另外每个对象具体有哪些属性和方法, 可以参考jmeter对应的接口文档



参考官方文档  http://jmeter.apache.org/usermanual/component_reference.html#BeanShell_PreProcessor

posted on 2017-10-22 09:19  测试小小  阅读(3050)  评论(0编辑  收藏  举报