JSON Extractor,__setProperty,__P,vars,props用法比較
功能:
JSON Extractor
JSON提取器,常用來提取目前請求響應裡的值,如登入token
作用域:目前線程組
官方文檔解釋: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後面
注:該函數的參數無需使用雙引号引用
官方文檔解釋: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,但不會存屬性值
官方文檔解釋: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:變量名,string類型
value:變量值,string類型
作用域:目前線程組,必須在beanshell中使用
vars.get函數用來擷取屬性值
var:變量名,需要使用雙引号引用變量名,即vars.get(“var”)
作用域:目前線程組,必須在beanshell中使用
props.put函數用來設定屬性值
var:變量名,string類型
value:變量值,string類型
作用域:跨線程組使用,必須在beanshell中使用
props.get函數用來擷取屬性值
var:變量名,需要使用雙引号引用,即props.get(“var”)
作用域:跨線程組使用,必須在beanshell中使用
props.get函數用來移除屬性
var:變量名,需要使用雙引号引用,即props.get(“var”)
作用域:跨線程組使用,必須在beanshell中使用