当前位置:网站首页>BeanShell 内置变量 ctx
BeanShell 内置变量 ctx
2022-07-22 18:10:00 【农耕园】
1 简介
通过它可以轻松的访问当前线程的上下文
在 JMeter 内部,ctx映射为 org.apache.jmeter.threads 的 JMeterContext 类 由于JMeterContext
不具有线程安全性,故仅适用于在单线程中使用
官方文档:https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
2 常用方法
2.1 getVariables
方法声明
public JMeterVariables getVariables()
功能:获取JMeter当前线程的所有变量
vars.put("name","shenzhen");
shen = ctx.getVariables().get("name");
log.info("name value is "+ shen);
结果:
2.2 getProperties
方法声明
public Properties getProperties()
功能:获取所有的JMeter属性
sh = ctx.getProperties().getProperty("sampleresult.default.encoding");
log.info("sampleresult.default.encoding value is "+sh);
结果:
2.3 getPreviousResult
方法声明
public SampleResult getPreviousResult()
功能:获取前一个取样器的结果
import org.apache.jmeter.samplers.SampleResult
SampleResult rsp= ctx.getPreviousResult();
String sh= rsp.getResponseDataAsString();
log.info("\n"+sh);

结果:
2.4 getCurrentSampler
方法声明
public Sampler getCurrentSampler()
功能:获取当前取样器对象
shs =ctx.getCurrentSampler().getName();
log.info("csn value is "+shs);
结果:
2.5 getPreviousSampler
方法声明
public Sampler getPreviousSampler()
功能:获取前一个取样器对象
shs =ctx.getPreviousSampler().getName();
log.info("csn value is "+shs);
结果:
2.6 getThreadNum
方法声明
public int getThreadNum()
功能:获取当前线程组下的线程编号(编号从0开始)
2.7 getThread
方法声明
public JMeterThread getThread()
功能:获取线程对象
shs =ctx.getThreadNum();
log.info("csn value is "+shs);
shsname =ctx.getThread().getThreadName();
log.info("shsname is "+shsname);
结果:
2.8 getThreadGroup
方法声明
public AbstractThreadGroup getThreadGroup()
功能:获取线程组对象
shs =ctx.getThreadGroup().getName();
log.info("csn value is "+shs);

边栏推荐
- 2021-06-03pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
- 第二天总结及测试用例作业
- Learn the MD of amber t3.3: implicit solvent model (GB)
- jmeter压力测试指标解释
- 学习Amber T3.3:隐式溶剂模型(GB)的MD
- Probe into JVM
- À propos du montage de fond, de la gestion des processus
- 测试前言2
- How OpenGL handles errors
- appium自动化测试,实例分享
猜你喜欢
随机推荐
Selenium基础知识 自动登录百度贴吧
Learn the input file parameters of amber software MD
Appium automated testing, instance sharing
Learn the MD of amber t3.3: implicit solvent model (GB)
软件生命周期---W模型
web端接口数据一键复制导入postman
关于后台挂载,进程管理的学习
[original] software test example guidance
软件测试流程
Math。round,数值取整底层代码解析
amber教程4.6:对体系氢键分析
Learn amber tutorial A17: umbrella sampling and drawing the potential energy surface of alanine tripeptide
使用禅道的流程
按是否运行源代码划分: 静态测试和动态测试
关于如何在终端设置有颜色的字体
Shallow shaking automatic test
使用pip使用报错:pip is configured with locations that require TLS/SSL
[Huang ah code] getting started with MySQL - 1. SQL execution process
课后练习01---QQ登录
Software testing process








