当前位置:网站首页>Jmeter之BeanShell详解和夸线程调用
Jmeter之BeanShell详解和夸线程调用
2022-06-29 19:49:00 【fish_study_csdn】
Jmeter中常用的BeanShell
前置处理器:BeanShell Preprocess
采样器:BeanShellSampler
后置处理器:BeanShell PostProcess
断言:BeanShell断言
Jmeter中的常用内置变量

具体应用:
后置处理器的应用:

jmeter 夸线程调用
前面讲了如何使用正则表达式提取值,一般提取的值在同一个线程里,随意哪个请求都是可以引用的,那如果别的线程组也想引用怎么办呢?这时就涉及到一个全局变量的知识点了,话不多说,直接实例走起。
1、BeanShell创建全局变量(跨线程组):可以用Beanshell取样器或者Beanshell后置处理器
1)创建一个局部的变量(线程组内):token
2)使用Beanshell调用创建的局部变量token,并将全局变量命名为newtoken,示例${__setProperty(newtoken,${token},)}
3)跨线程组调用全局变量
方法1:${__P(newtoken)}; //调用全局变量
方法2:${__property(newtoken)}; //也可以这样调用全局变量,和上面的写法是等价的
方法3:Beanshell前置处理器-将newtoken拿过来赋值给token1,然后可以${token1}引用
String a1=props.get("newtoken");
vars.put("token1",a1)
夸线程 实战 演示
1、在【登录】线程组的[统一登录]请求下,右键>添加>后置处理器>正则表达式,把统一登录成功后的响应结果里的token用正则表达式提取出来,引用名称是“token”。

添加beanshell 后置处理器:
${__setProperty(new_token,${token},)}; #将局部变量token 赋值给全局变量new_token
String a=vars.get("token"); # 获取局部变量给变量a
log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");#打印日志 方便排查问题
log.info("a="+a);#打印变量a 方便排查局部变量的值是否错误
新建查询线程:
添加http请求:
添加beanshell预处理程序:

String a1 = props.get("new_token"); #读取全局变量new_token 并赋值给a1
vars.put("token2",a1); #把a1 赋值给 token2
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
log.info("token2="+token2);#打印token2在http请求头中使用token2变量:

如果直接运行,通过日志发现,先运行查询线程,后运行登录线程,所以一直获取不到token,查询线程失败。
解决办法:
1)在测试计划中 选择独立运行每个线程组

2)在查询线程中添加固定定时器

边栏推荐
- ASP.Net Core创建Razor页面上传多个文件(缓冲方式)(续)
- 测试方法学习
- There are more than 20 databases in a MySQL with 3306 ports. How can I backup more than 20 databases with one click and do system backup to prevent data from being deleted by mistake?
- La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre
- 【观察】软通动力刘天文:拥抱变化“顺势而为”,做中国数字经济“使能者”...
- With these four security testing tools, software security testing can be said so easy!
- Linux安装MySQL8
- 4-1 port scanning technology
- 通过MeterSphere和DataEase实现项目Bug处理进展实时跟进
- shell bash脚本注意:单行末尾转义符 \ 后千万不能有其他无关字符(多行命令)
猜你喜欢

shell bash脚本注意:单行末尾转义符 \ 后千万不能有其他无关字符(多行命令)

Lock4j -- distributed lock Middleware -- customize the logic of lock acquisition failure

CorelDRAW最新24.1.0.360版本更新介绍讲解

Common knowledge of ECS security settings

As the "only" privacy computing provider, insight technology is the "first" to settle in the Yangtze River Delta data element circulation service platform

Kdd 2022 | prise en compte de l'alignement et de l'uniformité des représentations dans le Filtrage collaboratif

Exploration and practice of NLP problem modeling scheme

雲服務器的安全設置常識

idea中方法上没有小绿色三角

How is the combination of convolution and transformer optimal?
随机推荐
nacos 问题
2022年深圳市福田区支持招商引资若干政策
shell bash脚本注意:单行末尾转义符 \ 后千万不能有其他无关字符(多行命令)
数据安全解决方案的大时代
一个mysql里有3306端口下,一个mysql有20多个数据库,怎么一键备份20多个数据库,做系统备份,防止数据误删除?
ArrayList&lt; Integer&gt; Use = = to compare whether the values are equal, and -129=- 129 situation thinking
【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
The era of data security solutions
QC protocol + Huawei fcp+ Samsung AFC fast charging 5v9v chip fs2601 application
【网络方向实训】-企业园区网络设计-【Had Done】
Classic illustration of K-line diagram (Collection Edition)
软件测试逻辑覆盖相关理解
物理验证LVS流程和技术点滴(上)
[USB flash disk test] in order to transfer the data at the bottom of the pressure box, I bought a 2T USB flash disk, and the test result is only 47g~
Nacos problem
MySQL remote connection
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
WPS and Excelle
Notepad++--宏(记录操作过程)
Canonical engineers are trying to solve the performance problem of Firefox snap