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 @   沙丘蚂蚁慢慢爬  阅读(464)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2021-04-13 JMeter常用函数---__time()
点击右上角即可分享
微信分享提示