1. 程式人生 > >jmeter 中後置處理器 JSR223 使用到的方法

jmeter 中後置處理器 JSR223 使用到的方法

1. log:用來記錄日誌檔案,寫入到jmeber.log檔案,使用方法:log.info(“This is log info!”);

2. ctx(JmeterContext)通過它來訪問context,使用方法可參考:org.apache.jmeter.threads.JMeterContext。

3. vars - (JMeterVariables):操作jmeter變數,提供讀取/寫入訪問變數的方法。這個變數實際引用了JMeter執行緒中的區域性變數容器(本質上是Map),它是測試用例與BeanShell互動的橋樑,常用方法:

   a) vars.get(String key):從jmeter中獲得變數值

   b) vars.put(String key,String value):資料存到jmeter變數中

   c) vars.putObject("OBJ1",new Object());

 4.  props - (JMeterProperties - class Java.util.Properties):操作jmeter屬性,該變數引用了JMeter的配置資訊,可以獲取Jmeter的屬性,它的使用方法與vars類似,但是隻能put進去String型別的值,而不能是一個物件。對應於java.util.Properties。

   a) props.get("START.HMS"); 注:START.HMS為屬性名,在檔案jmeter.properties中定義

   b) props.put("PROP1","1234");

 5.  prev - (SampleResult):獲取前面的sample取樣的結果,常用方法:

   a) getResponseDataAsString():獲取響應資訊

   b) getResponseCode() :獲取響應code

更多方法可參考:org.apache.jmeter.samplers.SampleResult

  6.  sampler - (Sampler):gives access to the current sampler 訪問當前取樣