loadrunner 引數化取值方式詳解
引數化對話方塊中與引數取值方式有關的區域如下,在忘記的時候儲存下來,以便於即使檢視。
改變引數化的取值方式,關鍵在於Select next row和Update value on這兩個選項。
Select next row包括以下選項:
- Sequential:順序方式
- Random:隨機方式
- Unique:唯一方式
Update value on包括如下選項:
- Each iteration:每次迭代更新取值
- Each occurrence:每次取值更新
- Once:只更新一次
以下程式碼以登入介面和引數化進行演示,引數化檔案中有2個值
1 2 3 4 5 6 7 8 9 10 |
lr_output_message( "login_username:%s" ,lr_eval_string( "{login_username}" ));<br><br>web_custom_request( "login" ,
"URL=http://192.168.44.130:8080/mobile/api/user/login" ,
"Method=POST" ,
"TargetFrame=" ,
"Resource=0" ,
"Referer=" ,
"Mode=HTTP" ,
"EncType=application/json;charset=utf-8" ,
"Body={\"mobile\":\"{login_username}\",\"password\":\"123456\"}" ,
LAST);
|
引數化檔案中的資料為:
13141140050 13141140058
第一種取值方式:Sequential+Each iteration,設定迭代次數為3次,引數取值結果為:
Starting iteration 1.
Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989]
Starting action Action.
Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050"
Action.c(18): login_username:13141140050
Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355]
Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050"
Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385]
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Notify: Next row for parameter login_username = 2 [table = login_username].
Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'.
Starting action Action.
Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140058"
Action.c(18): login_username:13141140058
Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355]
Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058"
Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385]
Ending action Action.
Ending iteration 2.
Starting iteration 3.
Notify: Next row for parameter login_username = 1 [table = login_username].
Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'.
Starting action Action.
Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050"
Action.c(18): login_username:13141140050
Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355]
Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050"
Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385]
Ending action Action.
Ending iteration 3.
第二種取值方式:Sequential+Each occurrence,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Notify: Next row for parameter login_username = 1 [table = login_username]. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Starting action Action. Action.c(18): Notify: Next row for parameter login_username = 1 [table = login_username]. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
第三種取值方式:Sequential+Once,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
第四種取值方式:Random+Each iteration,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(18): login_username:13141140058 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Notify: Next row for parameter login_username = 1 [table = login_username]. Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Notify: Next row for parameter login_username = 2 [table = login_username]. Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(18): login_username:13141140058 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
第五種取值方式:Random+Each occurrence,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Notify: Next row for parameter login_username = 1 [table = login_username]. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Starting action Action. Action.c(18): Notify: Next row for parameter login_username = 1 [table = login_username]. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
第六種取值方式:Random+Once,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
第七種取值方式:Unique+Each iteration
這種取值方式,又可以有以下幾種設定:
當值不足時,可以選擇以下3種方式:
1)、中斷虛擬使用者
2)、迴圈取引數中的值,返回到第一行取值
3)、取最後一行值
以下執行結果以Abort Vuser為例執行,其它情況可自行設定執行,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Notify: Next row for parameter login_username = 2 [table = login_username]. Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(18): login_username:13141140058 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Error: Parameter 'login_username': No more unique values for this parameter in table 'login_username.dat' [unique range is 1-2]. The Vuser is aborted according to "When Out Of Values" policy. Action was aborted. Ending Vuser...
第八種取值方式:Unique+Each occurrence,引數不夠用時,也會報錯,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '1'. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Next row for parameter login_username = 2 [table = login_username]. Action.c(20): Notify: Getting new value for parameter 'login_username': table = 'login_username.dat' column = '0' row = '2'. Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140058" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Error: Parameter 'login_username': No more unique values for this parameter in table 'login_username.dat' [unique range is 1-2]. The Vuser is aborted according to "When Out Of Values" policy. Abort was called from an action. Ending Vuser...
第九種取值方式:Unique+Once,引數不夠用時,也會報錯,設定迭代次數為3次,引數取值結果為:
Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 2. Starting iteration 3. Starting action Action. Action.c(18): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(18): login_username:13141140050 Action.c(20): web_custom_request("login") started [MsgId: MMSG-26355] Action.c(20): Notify: Parameter Substitution: parameter "login_username" = "13141140050" Action.c(20): web_custom_request("login") was successful, 361 body bytes, 157 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 3.
總結:
本文轉載於:loadrunner 引數化取值方式詳解