__setProperty
${__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.
該函數(shù)用來給JMeter屬性設(shè)置值凿叠,默認返回值為空字符串涩笤,所以函數(shù)在任何地方被調(diào)用都是有效的
Property Name:要設(shè)置的屬性名,必要屬性
Property Value:要設(shè)置的屬性的值盒件,必要屬性
True/False:原值是否要返回蹬碧,非必要屬性;當設(shè)置為“true”炒刁,將返回原始值
作用域:跨線程組調(diào)用恩沽,可以在任意地方調(diào)用,但不能跟在import xxx后面
注:該函數(shù)的參數(shù)無需使用雙引號引用
__property
${__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.
該屬性函數(shù)返回JMeter屬性的值翔始,如果找不到屬性值且沒有提供默認值罗心,則直接返回屬性名里伯。在提供了默認值時就不需要寫函數(shù)名(這里是指重用此函數(shù)計算的值的引用名,即變量名)渤闷,它的參數(shù)可以設(shè)置為null疾瓮,此時該變量將直接被忽略。
property name:要檢索的屬性名飒箭,必填
variable name:重用該函數(shù)計算的值的引用名狼电,非必填
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.
這是簡化版的屬性函數(shù)削饵,旨在為用戶在命令行使用屬性定義岩瘦。它不像__property函數(shù)那樣有可以存值的變量,并且如果沒有提供默認值窿撬,側(cè)假定默認給1启昧,原因是它對常見的測試變量(如循環(huán)、線程數(shù)劈伴、ramp up等)有效
Property Name:要檢索的屬性名密末,必要屬性
Default Value:默認值,不填的話會默認設(shè)置1跛璧,非必要屬性
作用域:可跨線程使用
注:因為該函數(shù)只允許使用兩個參數(shù)严里,且必須使用逗號分隔,如果在第二個參數(shù)值中也存在逗號追城,需要使用“\”反斜線轉(zhuǎn)義刹碾,否則函數(shù)無效,如下:
${__P(prop1, www.baidu.com)} : 當prop1未定義時座柱,函數(shù)返回 www.baidu.com
${__P(prop1, www.baidu.~迷帜!@#¥%……&*()——+‘;com)} : 當prop1未定義時色洞,函數(shù)返回 www.baidu.~戏锹!@#¥%……&*()——+‘;com(非逗號的其他符號基本都能正常顯示)
${__P(prop1, www.baidu\,com)} : 當prop1未定義時火诸,函數(shù)返回 www.baidu,com
${__P(prop1, www.baidu,com)} : 當prop1未定義時锦针,函數(shù)沒有任何返回
vars
vars.put(var, value)
vars.put函數(shù)用來設(shè)置屬性值
var:變量名,string類型
value:變量值,string類型
作用域:當前線程組伞插,必須在beanshell中使用
vars.get(var)
vars.get函數(shù)用來獲取屬性值
var:變量名割粮,需要使用雙引號引用變量名,即vars.get(“var”)
作用域:當前線程組媚污,必須在beanshell中使用
props
props.put(var, value)
props.put函數(shù)用來設(shè)置屬性值
var:變量名舀瓢,string類型
value:變量值,string類型
作用域:跨線程組使用耗美,必須在beanshell中使用
props.get(var)
props.get函數(shù)用來獲取屬性值
var:變量名京髓,需要使用雙引號引用,即props.get(“var”)
作用域:跨線程組使用商架,必須在beanshell中使用
props.remove(var)
props.get函數(shù)用來移除屬性
var:變量名堰怨,需要使用雙引號引用,即props.get(“var”)
作用域:跨線程組使用蛇摸,必須在beanshell中使用
轉(zhuǎn)載于:https://blog.csdn.net/evanzhang_z/article/details/102715619