jmeter Variables

来源:互联网 发布:怎么检测网络是否正常 编辑:程序博客网 时间:2024/06/05 17:10

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”);

1 0
原创粉丝点击