Jmeter日常--beanshellSample中内置变量 prev

前言:

日常通过jmetet编写脚本用的最多的是:vars(get(),put(),getObject(),putObject(),

其实还有一些内置方法及官方文档,如下:

  • 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()); vars.getObject("OBJ2");
  • 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

ctx 地址:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html

vars 地址:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html

prev地址:http://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

 

prev介绍:

    prev 提供对当前取样器结果的访问能力
    prev 映射 org.apache.jmeter.samplers 的 SampleResult 类
    官方文档: https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

 

用法:

实际上需要通过拿到取样器的结果进行提取进行参数化,就可以通过prev进行,

SampleResult类型提供提取:头信息,响应码,子结果等等方法,同样也有设置头信息,响应结果 等等的方法

#调用方法,直接通过prev调用方法
String response = prev.getResponseCode()
log.info(response)#打印在日志上

 

其他方法:

 

 

 

 

 

 

 

参考:

https://www.cnblogs.com/tallme/p/5847321.html

https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

 

posted @ 2022-04-13 15:31  沙丘蚂蚁慢慢爬  阅读(437)  评论(0编辑  收藏  举报