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.

Pattern Matching Macro for Excel



Sub LookUpMatch()
    Dim wsLookup As Worksheet
    Dim wsMatch As Worksheet
    Set wsLookup = Sheets("LookUp")
    Set wsMatch = Sheets("Master")

    Dim LastRow As Long
    Dim RecordCount As Long
    LastRow = 1
   
    wsMatch.Activate
    LastRow = wsMatch.Range("A" & Rows.Count).End(xlUp).Row + 1
 
 
    wsMatch.Range("a1", wsMatch.Range("a1").End(xlDown)).Select
           
   
    For Each c In Selection.Cells
       
    sRaw = c.Value
           
        'Select wsLookUp.A range
        'Loop through each value to see if inStr matches.
        'If InStr Matches, Select original cell
        'In next cell add "I"
        'Loop
        'MsgBox sRaw
        wsLookup.Activate
        wsLookup.Range("a1", wsLookup.Range("a1").End(xlDown)).Select
       
        For Each d In Selection.Cells
        sLookUp = d.Value
        TestPos = InStr(LCase(sRaw), LCase(sLookUp))
       
        If TestPos > 0 Then
           
            MsgBox "Found " & sLookUp & " in " & sRaw
       
       
        Exit For
        End If
           
       
        Next d
       
       
    Next c
   
   
   
MsgBox ("All Done")
End Sub