天天看點

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