The LoadRunner Blog

Monday, October 03, 2016

[b]The Test Case:[/b]

You have to retrieve the a random "nth" element from multiple wrsp arrays (of equal length) and submit them in your next web submit data.

Eg - a Banking application retreives multiple rows showing Cheque Number, A Unique Id Number, Balance Amount and Date. All four values have to be captured and submitted in the next webcustom request. So if you are retrieving the 7th Check Number, you have to retrieve the 7th Unique Id Number, the 7th Balance Amount, the 7th Unique Date etc.. (Where 7 is generated randomly). In this case lr_paramarr_random wont work as there is no guarantee that they will all retrieve the same element from the multiple arrays.

[b]The Code[/b]

--------------
action(){
int rNum;


web_reg_save_param("PrmCHECK", "LB=id=check value=", "RB=>", "ORD=ALL", LAST);
web_reg_save_param("PrmDIN", "LB=id=dinum value=", "RB=>", "ORD=ALL", LAST);
web_reg_save_param("PrmDATE", "LB=id=Ddate value=", "RB=>", "ORD=ALL", LAST);
web_reg_save_param("PrmBAL", "LB=id=bal value=", "RB=>", "ORD=ALL", LAST);


web_url("Your URL step", ........... LAST);


/*Above four wrsps will capture values in four parameter arrays. */


rNum = 1 + rand() % lr_paramarr_len("PrmCHECK");
/* Generates a Random Number between 1 and Length of Paramater array for PrmCHECK*/


lr_save_string(lr_paramarr_idx("PrmCHECK", rNum),"CHECKNUM");
lr_save_string(lr_paramarr_idx("PrmDATE", rNum),"DATE");
lr_save_string(lr_paramarr_idx("PrmDIN", rNum),"DINID");
lr_save_string(lr_paramarr_idx("PrmBAL", rNum),"BALANCE");
/* above retrieves the same nth random element from all four parameter arrays*/

web_url("Click on Random Result", "URL=https:// index.cgi?check={CHECKNUM}&dt={DATE}&id={DINID}&bal={BALANCE}", LAST);

return 0;
}

Note: This came up as an evaluation at a hands on Interview exercise I gave recently.

0 Comments:

Post a Comment

<< Home