我们在Loadrunner的测试过程中时常需要随机选择一个对象,进行下一步的操作,比如一个Table中有100行,测试的时候不能每次都选择同一行进行测试,而是要随机选择不同行,这样才能更好的模拟用户的真实情况
第一步,找出返回Table对象的请求,进行关联,关联的时候使用Ordinal=all找出所有的行
/*Correlation comment - Do not change! Original value=‘aQoEp51‘ Name =‘all_the_Listcell‘ Type =‘Manual‘*/ web_reg_save_param_ex( "ParamName=all_the_Listcell", "LB/IC=zul.sel.Listcell\‘,\‘", "RB/IC=\‘,{$onClick:true,sclass:\‘yw-listview-cell\‘},{},", "Ordinal=all", SEARCH_FILTERS, "Scope=Body", LAST); web_submit_data("zkau_59", "Action=https://pet.sonystyle.com.cn/backoffice/zkau", "Method=POST", "RecContentType=text/plain", "Referer=https://pet.sonystyle.com.cn/backoffice/", "Snapshot=t256.inf", "Mode=HTML", ITEMDATA, "Name=dtid", "Value={clientInfo}", ENDITEM, "Name=cmd_0", "Value=echo", ENDITEM, "Name=opt_0", "Value=i", ENDITEM, "Name=uuid_0", "Value={mainWin}", ENDITEM, "Name=data_0", "Value={\"\":[\"{data_9}\"]}", ENDITEM, LAST);
第二步,判断关联是否成功,若成功则从关联对象all_the_Listcell中随机选取一个值,存储在one_of_the_Listcell中
arrSize=lr_paramarr_len("all_the_Listcell"); if(arrSize>0){ lr_save_string(lr_paramarr_random("all_the_Listcell"),"one_of_the_Listcell"); }else{ lr_error_message("Search_Condition4_OrderStatus have no response! OrderStatus=%s",lr_eval_string("{OrderStatus}")); lr_end_transaction("BackOffice_TC02_05_Search_Condition4_OrderStatus",LR_FAIL); return 0; }
第三步,调用
web_submit_data("zkau_32", "Action=https://pet.sonystyle.com.cn/backoffice/zkau", "Method=POST", "RecContentType=text/plain", "Referer=https://pet.sonystyle.com.cn/backoffice/", "Snapshot=t91.inf", "Mode=HTML", ITEMDATA, "Name=dtid", "Value={clientInfo}", ENDITEM, "Name=cmd_0", "Value=onClick", ENDITEM, "Name=uuid_0", "Value={one_of_the_Listcell}", ENDITEM, "Name=data_0", "Value={\"pageX\":412,\"pageY\":439,\"which\":1,\"x\":107,\"y\":29}", ENDITEM, LAST);