当前位置:网站首页>JMeter BeanShell explanation and thread calling
JMeter BeanShell explanation and thread calling
2022-06-29 19:56:00 【fish_ study_ csdn】
Jmeter Commonly used BeanShell
Preprocessor :BeanShell Preprocess
Sampler :BeanShellSampler
Post Processors :BeanShell PostProcess
Assertion :BeanShell Assertion
Jmeter Common built-in variables in

Specific application :
Post processor applications :

jmeter Kua thread calls
We talked about how to use regular expressions to extract values , Generally, the extracted values are in the same thread , Any request can be referenced , What if other thread groups also want to refer to ? At this point, it involves the knowledge of a global variable , Don't talk much , Direct examples start .
1、BeanShell Create global variables ( Cross thread group ): It can be used Beanshell Sampler or Beanshell Post Processors
1) Create a local variable ( Within the thread group ):token
2) Use Beanshell Call the created local variable token, And name the global variable newtoken, Example ${__setProperty(newtoken,${token},)}
3) Calling global variables across thread groups
Method 1:${__P(newtoken)}; // Call global variables
Method 2:${__property(newtoken)}; // You can also call global variables in this way , It is equivalent to the above writing
Method 3:Beanshell Preprocessor - take newtoken Take it and assign it to token1, Then you can ${token1} quote
String a1=props.get("newtoken");
vars.put("token1",a1)
Quart thread actual combat demonstration
1、 stay 【 Sign in 】 Thread group's [ Unified login ] Under request , Right click > add to > Post Processors > Regular expressions , Log in the response result after the unified login is successful token Use regular expressions to extract , The reference name is “token”.

add to beanshell Post Processors :
${__setProperty(new_token,${token},)}; # Put the local variable token Assign to global variable new_token
String a=vars.get("token"); # Get local variables to variables a
log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");# Print log It's easy to troubleshoot
log.info("a="+a);# Print variables a It is convenient to check whether the value of local variables is wrong 
Create a new query thread :
add to http request :
add to beanshell Preprocessor :

String a1 = props.get("new_token"); # Read global variables new_token And assign it to a1
vars.put("token2",a1); # hold a1 Assign a value to token2
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
log.info("token2="+token2);# Print token2stay http In the request header token2 Variable :

If it runs directly , Log discovery , Run the query thread first , After running the login thread , So I can't get token, Query thread failed .
terms of settlement :
1) In the test plan Choose to run each thread group independently

2) Add a fixed timer to the query thread

边栏推荐
- [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~
- 软件测试逻辑覆盖相关理解
- Sword finger offer 66 Building a product array
- 【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
- ArrayList&lt; Integer&gt; Use = = to compare whether the values are equal, and -129=- 129 situation thinking
- 【精品】pinia详解
- 罗清启:高端家电已成红海?卡萨帝率先破局
- Linux Installation mysql5
- npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
- 自动获取本地连接及网络地址修改
猜你喜欢

苹果iPhone手机升级系统内存空间变小不够如何解决?

Flume理论

通过MeterSphere和DataEase实现项目Bug处理进展实时跟进

Common knowledge of ECS security settings

There is no small green triangle on the method in idea

Etcd database source code analysis - put process of server

如何设置 Pod 到指定节点运行

MySQL remote connection

data link layer

Flume configuration 3 - interceptor filtering
随机推荐
Etcd database source code analysis - put process of server
4-1 port scanning technology
以其他组件为代价的性能提升不是好提升
Flutter calls Baidu map app to realize location search and route planning
2022年理财利率都降了,那该如何选择理财产品?
Classic illustration of K-line diagram (Collection Edition)
【精品】pinia详解
[observation] softcom power liutianwen: embrace change and "follow the trend" to become an "enabler" of China's digital economy
There is no small green triangle on the method in idea
nacos 问题
Go: how to write a correct UDP server
2022年深圳市福田区支持招商引资若干政策
云服务器的安全设置常识
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?
What about frequent network disconnection of win11 system? Solution to win11 network instability
Kdd 2022 | prise en compte de l'alignement et de l'uniformité des représentations dans le Filtrage collaboratif
2022年深圳市福田区支持先进制造业发展若干措施
Flume配置4——自定義Source+Sink
Sword finger offer 59 - ii Maximum value of the queue
Exploration and practice of NLP problem modeling scheme