lr_paramarr_random()函数的作用为:从一个参数数组中随机抽取一个值并以字符串形式返回。其使用方式及返回方式如下:
char * lr_paramarr_random( const char * paramArrayName);
该函数在某些测试场景下或许比较有用,如随机选择页面中一个下拉框中的值。
1 <html> 2 <head> 3 </head> 4 <body> 5 <select id="mySelect"> 6 <option>bag</option> 7 <option>book</option> 8 <option>apple</option> 9 </select> 10 11 </body> 12 </html>
将该WEB页丢到Apache进行发布。
1 Action() 2 { 3 char *str; 4 web_reg_save_param( 5 "Names", 6 "LB=<option>", 7 "RB=</option>\r\n", 8 "Ord=all", 9 10 LAST); 11 12 web_url("Test.html", 13 "URL=http://127.0.0.1:8080/Test.html", 14 "Resource=0", 15 "RecContentType=text/html", 16 "Referer=", 17 "Snapshot=t1.inf", 18 "Mode=HTML", 19 LAST); 20 21 str = lr_paramarr_random("Names"); 22 // lr_save_string(lr_paramarr_random("Names"),"name"); 通过 lr_save_string()函数,将该随机返回的参数保存到参数 ‘name‘ 中 23 lr_message("the name is Error : %s",str); 24 // lr_message("the name is : %s",lr_eval_string("{name}")); 25 //打印出该 ‘name‘ 参数的值 26 return 0; 27 }
1 Starting action Action. 2 Action.c(4): Registering web_reg_save_param was successful [MsgId: MMSG-26390] 3 Action.c(12): Notify: Saving Parameter "Names_1 = bag". 4 Action.c(12): Notify: Saving Parameter "Names_2 = book". 5 Action.c(12): Notify: Saving Parameter "Names_3 = apple". 6 Action.c(12): Notify: Saving Parameter "Names_count = 3". 7 Action.c(12): web_url("Test.html") was successful, 232 body bytes, 308 header bytes [MsgId: MMSG-26386] 8 Action.c(22): Notify: Parameter Substitution: parameter "Names_count" = "3" 9 Action.c(22): Notify: Parameter Substitution: parameter "Names_2" = "book" 10 Action.c(22): Notify: Saving Parameter "name = book". 11 Action.c(24): Notify: Parameter Substitution: parameter "name" = "book" 12 the name is : book 13 Ending action Action.
脚本解释:
1、运行完web_url()函数后,web_reg_save_param()函数把三个参数的值保存在了 ‘Names’ 参数数组中。
2、lr_paramarr_random()函数从 Names 参数数组中,随机抽取一个值并以字符串的形式返回(本次返回的值是 ‘book‘ )
3、打印输出该值
LoadRunner函数示例:lr_paramarr_random(),布布扣,bubuko.com
LoadRunner函数示例:lr_paramarr_random()
原文:http://www.cnblogs.com/zhm450/p/3723984.html