当前位置:网站首页>Tips for using the built-in variable vars in BeanShell
Tips for using the built-in variable vars in BeanShell
2022-07-24 05:18:00 【Agricultural garden】
1 brief introduction
BeanShell There are built-in variables ,JSR223 There will also be corresponding variables
vars Is the most commonly used JMeter One of the variables
stay JMeter Inside , mapping org.apache.jmeter.threads Of JMeterVariables class
vars Provides the ability to read and write current thread variables
be-all JMeter The variables are java character string
If you need to store data in a JMeter variable , It needs to be converted to a string first
Official documents :https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html
2 Common methods
2.1 getThreadName
Method statement
public String getThreadName()
function : Get the current running thread name
tn = vars.getThreadName();
log.info("Current thread name is "+tn);

result :
2.2 getIteration
Method statement
public int getIteration()
function : Gets the current iteration code of the thread
tn = vars.getIteration();
log.info("Current Iteration number is "+tn);
result :
2.3 put
Method statement
public void put(String key, String value)
function : Create or update string variables ,key Variable name ,value A variable's value
// First create the variable
vars.put("name","shenzhen");
vars.put("age","60"); // Can not write 20
mname =vars.get("name");
mage = vars.get("age");
log.info("---mname is-----"+mname);
log.info("----age is------"+ mage);
// Update variables
vars.put("age","24");
vage = vars.get("age");
log.info("-----mage is------ "+vage);
result :
2.4 get
Method statement
public String get(String key)
function : Get the value of a variable and convert it to a string , If the variable exists, the value is converted to a string , Otherwise return to null
//get The way
vars.put("color","green");
vcolor = vars.get("color");
log.info("---volor is---" + vcolor);
vars.putObject("aman",["name":"shenzhen","sex":1,"age":30,"city":"shanghai"]);
vaman = vars.get("aman");
log.info("----vaman is----"+vaman);
// Variable does not exist
vfont = vars.get("fonts");
log.info("----vfont is---"+vfont);

result :
2.5 putObject
Method statement
public void putObject(String key,Object value)
function : Create or update a non string variable .key Variable name ,value A variable's value
// Set up Value of non string variable :Numbers,Lists,Arrays,Maps
vars.putObject("number1",3.14);
vars.putObject("list1",[11,12,33,44]);
vars.putObject("array1",[1,2,3,4,5] as int[]);
vars.putObject("map1",["name":"shenzhen","sex":1,"age":30,"city":"shanghai"]);
vars.putObject("map2",["address":"jichang","phone":"16888"]);
// Get the value of the string variable Numbers,lists,Arrays,Maps
log.info("number1 is"+vars.getObject("number1").toString());
log.info("list1 count is "+vars.getObject("list1").size());
log.info("list1 first element is"+vars.getObject("list1").get(0));
log.info("array1 count is"+vars.getObject("array1").length);
log.info("map1's name is"+vars.getObject("map1").get("name"));
result :
2.6 getObject
Method statement
public Object getObject(String key)
function : Get the value of the variable ( Do not convert to string ). Returns... If the variable does not exist null
vars.putObject("pank",24);
vpank = vars.getObject("pank");
log.info("vpank is "+vpank);
vcontent =vars.getObject("content");
log.info("vcontent is "+vcontent);
result :
2.7 remove
Method statement
public Object remove(String key)
function : Delete a variable , And return the value of the variable , Returns... If the variable does not exist null
// Variable does not exist
v1 = vars.remove("shenzhen");
log.info("v1 is "+v1);
// Variable existence
vars.put("name","123");
v2 = vars.remove("name");
log.info("v2 is "+ v2);
result :
边栏推荐
- Infineon launched the world's first TPM security chip with post quantum encryption technology for firmware update
- )的低字节来反馈给应用层或者成多种格式文档:
- 【NumPy】
- Theoretical basis of machine learning
- Pointer learning diary (IV) use structure and pointer (linked list)
- Chapter 7 other neural network types
- 泛型和注解
- PXE efficient batch network installation
- Kingbase v8r6 cluster installation and deployment case - script online one click expansion
- The world's first large aerospace model came out. Wenxin's second supplement "Fuchun Mountain Residence map" is Baidu Pratt Whitney AI's perseverance
猜你喜欢

Jiang Xingqun, senior vice president of BOE: aiot technology enables enterprise IOT transformation

1、基于增量式生成遮挡与对抗抑制的行人再识别

High performance architecture design of wechat circle of friends

Context encoders: feature learning by painting paper notes

【深度学习】(三)图像分类

FTP file transfer protocol

Chapter 7 other neural network types

MapReduce concept

Bear market bottoming Guide

Blue Bridge Cup 31 day sprint 21 day (C language)
随机推荐
Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]
网NN计算能主机系统资e提供的NTCP
JDBC MySQL basic operations
反射
利用a*启发式搜索解决迷宫寻路问题
Use of fiddler packet capturing tool
The difference between statement and Preparedstatement and how to use placeholders
Blue Bridge Cup 31 day sprint 21 day (C language)
1. Input a 100 point score from the keyboard and output its grade according to the following principles: score ≥ 90, Grade A; 80 ≤ score < 90, grade B; 70 ≤ score < 80, grade C; 60 ≤ score < 70, grade
JMeter record the BeanShell written into excel instance caused by an automatic data generation
C primer plus learning notes - 5. Pointer
Mysq Database Constraints
Kingbase V8R6集群安装部署案例---脚本在线一键缩容
postgresql:在Docker中运行PostgreSQL + pgAdmin 4
ZY: modify host name
Theoretical basis of machine learning
[basic 7] - exceptions, capture and customize exceptions
Knowledge record of College Physics C in advance in summer [update]
The difference between run and start in thread class
Hcip day 3 - mGRE experiment