參數化對話框中與參數取值方式有關的區域如下:
改變參數化的取值方式,關鍵在於Select next row和Update value on這兩個選項。
Select next row包括以下選項:
- Sequential:順序方式
- Random:隨機方式
- Unique:唯一方式
Update value on包括如下選項:
- Each iteration:每次迭代更新取值
- Each occurrence:每次取值更新
- Once:只更新一次
以下代碼以登錄接口和參數化進行演示,參數化文件中有2個值
lr_output_message("login_username:%s",lr_eval_string("{login_username}"));
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.
總結: