jmeter Variables

本文介绍了如何在JMeter中使用Variable类进行变量的操作,包括获取和设置系统变量的方法。通过put和get方法可以轻松实现变量的传递和使用,这对于自动化测试脚本的编写尤其有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jmeter脚本编辑器中,可以通过Variable类,获取用户自定义的变量,也可以把接口中获取的变量变成jmeter的系统变量。
beanShell中
可以直接使用vars. 来调用Variable中的方法。
以下介绍几种Variable中的方法。
用到最多的是put和get方法
导入 import org.apache.jmeter.threads.JMeterVariables;
1.获取变量
public String get(String key)
Gets the value of a variable, coerced to a String.
Parameters:
key - the name of the variable
Returns:
the value of the variable, or null if it does not exist
使用方法:my_name 是定义的用户变量
String str = vars.get(“my_name”);
通过日志打印出来:log.info(“str_my_name:”+str);
2.通过beanShell定义系统变量
public void put(String key,
String value)
Creates or updates a variable with a String value.
Parameters:
key - the variable name
value - the variable value
使用方法:
第一个参数是变量名,第二个参数是变量值
vars.put(“my_name_var”, my_name_var);
3.获取变量对象
public Object getObject(String key)
Gets the value of a variable (not converted to String).
Parameters:
key - the name of the variable
Returns:
the value of the variable, or null if it does not exist
使用方法:
Object strO = vars.getObject(“my_name”);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值