首页 > 编程知识 正文

常用文本函数有几种,几种常见的函数像

时间:2023-05-06 17:33:49 阅读:254501 作者:195

JSON Extractor,__setProperty,__P,vars,props用法比较

功能:

JSON Extractor

JSON提取器,常用来提取当前请求响应里的值,如登录token
作用域:当前线程组

${__setProperty(property name, property value, True/False)}

官方文档解释:The setProperty function sets the value of a JMeter property. The default return value from the function is the empty string, so the function call can be used anywhere functions are valid.

该函数用来给JMeter属性设置值,默认返回值为空字符串,所以函数在任何地方被调用都是有效的
Property Name:要设置的属性名,必要属性
Property Value:要设置的属性的值,必要属性
True/False:原值是否要返回,非必要属性;当设置为“true”,将返回原始值
作用域:跨线程组调用,可以在任意地方调用,但不能跟在import xxx后面
注:该函数的参数无需使用双引号引用

${__property(property name, variable name, default value)}

官方文档解释:The property function returns the value of a JMeter property. If the property value cannot be found, and no default has been supplied, it returns the property name. When supplying a default value, there is no need to provide a function name - the parameter can be set to null, and it will be ignored.

该属性函数返回JMeter属性的值,如果找不到属性值且没有提供默认值,则直接返回属性名。在提供了默认值时就不需要写函数名(这里是指重用此函数计算的值的引用名,即变量名),它的参数可以设置为null,此时该变量将直接被忽略。
property name:要检索的属性名,必填
variable name:重用该函数计算的值的引用名,非必填
default value:前面属性的默认值,非必填

举例:

${__property(user.dir)} - 返回user.dir的值${__property(user.dir,UDIR)} - 返回user.dir的值并将值存到UDIR${__property(abcd,ABCD,atod)} - 返回abcd属性的值,如果abcd未定义值,返回atod,并将值存到ABCD${__property(abcd,,atod)} - 返回abcd属性的值,如果abcd未定义值,返回atod,但不会存属性值 ${__P(property name, default value)}

官方文档解释:This is a simplified property function which is intended for use with properties defined on the command line. Unlike the __property function, there is no option to save the value in a variable, and if no default value is supplied, it is assumed to be 1. The value of 1 was chosen because it is valid for common test variables such as loops, thread count, ramp up etc.

这是简化版的属性函数,旨在为用户在命令行使用属性定义。它不像__property函数那样有可以存值的变量,并且如果没有提供默认值,侧假定默认给1,原因是它对常见的测试变量(如循环、线程数、ramp up等)有效
Property Name:要检索的属性名,必要属性
Default Value:默认值,不填的话会默认设置1,非必要属性
作用域:可跨线程使用
注:因为该函数只允许使用两个参数,且必须使用逗号分隔,如果在第二个参数值中也存在逗号,需要使用“”反斜线转义,否则函数无效,如下

${__P(prop1, www.baidu.com)} : 当prop1未定义时,函数返回 www.baidu.com${__P(prop1, www.baidu.~!@#¥%……&*()——+‘;com)} : 当prop1未定义时,函数返回 www.baidu.~!@#¥%……&*()——+‘;com(非逗号的其他符号基本都能正常显示)${__P(prop1, www.baidu,com)} : 当prop1未定义时,函数返回 www.baidu,com${__P(prop1, www.baidu,com)} : 当prop1未定义时,函数没有任何返回 vars.put(var, value)

vars.put函数用来设置属性值
var:变量名,string类型
value:变量值,string类型
作用域:当前线程组,必须在beanshell中使用

vars.get(var)

vars.get函数用来获取属性值
var:变量名,需要使用双引号引用变量名,即vars.get(“var”)
作用域:当前线程组,必须在beanshell中使用

props.put(var, value)

props.put函数用来设置属性值
var:变量名,string类型
value:变量值,string类型
作用域:跨线程组使用,必须在beanshell中使用

props.get(var)

props.get函数用来获取属性值
var:变量名,需要使用双引号引用,即props.get(“var”)
作用域:跨线程组使用,必须在beanshell中使用

props.remove(var)

props.get函数用来移除属性
var:变量名,需要使用双引号引用,即props.get(“var”)
作用域:跨线程组使用,必须在beanshell中使用

k8s部署RancherAnycast加速 绑定资源 AnycastEIPhelm使用

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。