当前位置:网站首页>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 :
边栏推荐
- IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
- Mysq Database Constraints
- PSO and mfpso
- Image painting for irregular holes using partial revolutions paper notes
- C primer plus learning notes - 5. Pointer
- Learning pyramid context encoder network for high quality image painting paper notes
- Transpose of array sparse matrix
- Do you want to have a robot that can make cartoon avatars in three steps?
- Teach you how to weld CAD design board bottom (for beginners) graphic tutorial
- MS simulated written test
猜你喜欢

Using a* heuristic search to solve maze routing problem
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

postgresql:在Docker中运行PostgreSQL + pgAdmin 4

Drools development decision table

Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem

利用a*启发式搜索解决迷宫寻路问题
![Embedded system transplantation [3] - uboot burning and use](/img/36/69daec5f1fe41bd3d0433d60816bba.png)
Embedded system transplantation [3] - uboot burning and use

Introduction to MapReduce

Chapter 7 other neural network types

Fiddler抓包工具的使用
随机推荐
[Huang ah code] Introduction to MySQL - 3. I use select *, and the boss directly rushed me home by train, but I still bought a station ticket
Support complex T4 file systems such as model group monitoring and real-time alarm. e
Rlib learning - [4] - algorithmconfig detailed introduction [pytoch version]
Chapter VI more supervision training
泛型和注解
I'm interested in reading efficient reading - the most cost-effective self investment
Memorandum 2022
C primer plus learning notes - 6. Arrays and pointers
Introduction to MapReduce
MapReduce concept
It is related to the amount of work and ho. Embedded, only one 70 should be connected
The difference between statement and Preparedstatement and how to use placeholders
Pointer learning diary (I)
Hcip day 3 - mGRE experiment
Drools development decision table
反射
MGRE and OSPF comprehensive experiment
Binary SCA fingerprint extraction black Technology: go language Reverse Technology
Performance test process
How can NFT, whose stars enter the market against the market, get out of the independent market?