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

Wednesday, April 28, 2010

L2 - EAD Renewal Letter / Check List

Okay, you are doing your own L2 EAD submittal, or renewal with the USCIS. Confused about the documentation you need to submit? Print out the text below.. replace the data in it and you are good to go. I have tried it once with good results.



  1. Dated: 7/16/2008
    To,
    USCIS Vermont Service Center
    75 Lower Welden Street,
    St. Albans, VT05479

    Dear Sir / Ma’am

    Please find enclosed the additional supporting documents for my e-filed Form I-765 for EAD renewal.

    Thank you

    (FIRSTNAME-L2 LASTNAME-L2)

    List of Document Copies enclosed

    Confirmation Receipt for E-filed I-765 – No EAC0880012345
    Original Form I-797D Mailer (from previous EAD)
    Front of Older EAD Card 088881234
    Back of Older EAD Card 088881234
    Personal Data Page of Passport B7654321 for LASTNAME-L2, FIRSTNAME-L2
    Personal Data Page of Passport B7654321 for LASTNAME-L2, FIRSTNAME-L2
    L2 Visa Page from Passport B7654321 along with Entry Stamp
    I-94 Front for LASTNAME-L2, FIRSTNAME-L2
    I-94 Back for LASTNAME-L2, FIRSTNAME-L2
    Passport Data Page for LASTNAME-L1, FIRSTNAME-L1 (L-1 Principal)
    Passport Data Page for LASTNAME-L1, FIRSTNAME-L1 (L-1 Principal)
    L1 Visa Page for LASTNAME-L1, FIRSTNAME-L1 along with Entry Stamp
    I-94 Front for LASTNAME-L1, FIRSTNAME-L1
    I-94 Back for LASTNAME-L1, FIRSTNAME-L1
    Certificate of Marriage for LASTNAME-L2, FIRSTNAME-L2 and LASTNAME-L1, FIRSTNAME-L1


Monday, April 16, 2007

Tackling Load Balancing and Redirects

Chid posted this on SQA Forums.com

-------------------------------

Okay, Here is a typical problem that I faced in scripting an application. The recorded and correlated code was something like this:


web_submit_data("GotoURL",
"Action=https://www.uat.com/123.cfm",
"Method=POST",
"RecContentType=text/html",
"Referer=https://www.uat.com/LCSvlt",
"Snapshot=t9.inf",
"Mode=HTTP",
ITEMDATA,
"Name=RETURN_URL", "Value={PrmRETURL}", ENDITEM,
"Name=INPUT_DATA", "Value={PrmINPUTDATA}", ENDITEM,
"Name=SIG_DATA", "Value={PrmSIGDATA}", ENDITEM,
LAST);

web_url("Firm-Wide Poll",
"URL=https://www2.uat.com/firmwidepoll/login.cfm",
"Resource=0",
"RecContentType=text/html",
"Referer=https://www2.uat.com/home/home.cfm",
"Snapshot=t12.inf",
"Mode=HTTP",
LAST);

Now the problem was after the first step, the user gets redirected to a URL designated by the load balancer - which is designated with a url starting with www and a numerical digit. So while the user was redirect to www2.uat.com the first time, the second time he logs in , he is redirected to www3.uat.com - invoking the older URl at this stage makes the script fail.

Did i hear someone say "wrsp .. stupid?"

Yup but wrsp didnt work - because the response from the redirected URL had header and body responses in relative urls.. you know "../logout.cfm" rather than "www2.uat.com/logout.cfm"..

so yes, the plain old vanilla wrsp did not work. Okay should I escalate this to the Lead developers? Will they make any changes in the UAT? Should I raise this in my next meeting.. Wait, lets check the friggin resources on the net first.

Then a search of the loadrunner group yahoo archives came up with a suggestion. One of the attributes of the wrsp function is IgnoreRedirections . Now the default is set to YES - signifying that LR will search the final response and not the responses in between. So you just set the attribute to NO, and LR will search the redirect response first and capture the value out of it. So finally, here is the working code :


web_reg_save_param ("RedirectURL", "LB=www", "RB=.uat.com", "IgnoreRedirections=No", LAST);


web_submit_data("GotoURL",
"Action=https://www.uat.com/123.cfm",
"Method=POST",
"RecContentType=text/html",
"Referer=https://www.uat.com/LCSvlt",
"Snapshot=t9.inf",
"Mode=HTTP",
ITEMDATA,
"Name=RETURN_URL", "Value={PrmRETURL}", ENDITEM,
"Name=INPUT_DATA", "Value={PrmINPUTDATA}", ENDITEM,
"Name=SIG_DATA", "Value={PrmSIGDATA}", ENDITEM,
LAST);

web_url("Firm-Wide Poll",
"URL=https://www{RedirectURL}.uat.com/firmwidepoll/login.cfm",
"Resource=0",
"RecContentType=text/html",
"Referer=https://www{RedirectURL}.uat.com/home/home.cfm",
"Snapshot=t12.inf",
"Mode=HTTP",
LAST);

Labels: , , ,

Tuesday, March 20, 2007

My Load Test » Blog Archive » LoadRunner CPC Exam

My Load Test » Blog Archive » LoadRunner CPC Exam

Stuart Moncrieff's page on the LoadRunner CPC Exam is a must read. While you are at it, you should also download the LR80Sp-StudySummary-03.pdf and the LR81CPC-StudySummary-01B.pdf files to know more about the CPS and CPC certifications. FWIW, the CPS appears to be rather basic. Will let you know when I do it.

Saturday, March 10, 2007

Replace x Character in your parameter with 'y'

A code snippet from ptrussell on sqaforums here

http://www.sqaforums.com/showthreaded.php?Cat=0&Number=362879&page=0&vc=1

Tells you how to replace some character in your parameter with another - in this case, replace a "+" with a " "

{
char *tmpstr;
int i;

tmpstr = lr_eval_string("{Map_Page_Street_Correlation}");

for (i = 0; tmpstr[i]; i++)
if (tmpstr[i] == '+') tmpstr[i] = ' ';
lr_save_string(tmpstr, "New_Street");
}
Jacqui posted another solution below

I thought I would throw this solution out there for general info. LR has a built in function to handle this. Here is an example....

web_convert_param("ParamName", "SourceString={Map_Page_Street_Correlation}","SourceEncoding=URL", "TargetEncoding=PLAIN", LAST);


Have a great weekend!
Jacqui

Labels: , , ,

Tuesday, November 21, 2006

File Download Test - getting downloaded file size

Giles on the SQAForum has given a code snippet to test for file download.
There are also a series of posts on the Loadrunner list that talks about how Loadrunner behaves in such a test. In short LR does not store a copy of the file , it just receives the packets and the data is then erased. You can however get the property of the files like download size, download time etc. Anyway back to Giles' solution


You simply call the function after the call to download the file.

Calling Action
Code:


Action()
{
web_url("GetPDF",
"URL=http://www.tfl.gov.uk/tfl/pdfdocs/colourmap.pdf",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Mode=HTML",
LAST);


/*Get File Statistics*/
funcFileDownload();


return 0;
}



Called Function:
Code:


float fFileDownloadSize, fFileDownloadTime, fFileDownloadRate;

funcFileDownload()
{
fFileDownloadSize = (web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE)/1024.); //in kilobytes
fFileDownloadTime = (web_get_int_property(HTTP_INFO_DOWNLOAD_TIME)/1000.); //in seconds
fFileDownloadRate = fFileDownloadSize/fFileDownloadTime; //in KB/s

lr_output_message("Size of download was %.0f kilobytes; Time of download was %.3f seconds", fFileDownloadSize, fFileDownloadTime);
lr_output_message("Rate of download was %.2f KB/sec", fFileDownloadRate);

return 0;
}

Tuesday, November 07, 2006

XML Custom Requests - and Responses

Okay, if you are 'testing' XML pages rather than the regular HTTP pages - you can use lr_xml_find to text-check your responses. Recently I was required to code a test that sends an XML File to a service and gets a return XML file. The following is the code that works. You can program many variants of XML tests. Refer to Pages 1115-1128 of the VUGen guide "Programming with the XML API" for further details


The Code:


Action()
{
//Save XML Data into Character Variable
char *xml_input=
""
"WEB"
"100"
"1234567"
""
"VTEST"
"USD"
"4111123456789022"
"123"
"2012"
""
""
"8"
"9"
"2006"
"";

//Move Character Variable value into Parameter for LR
lr_save_string(xml_input,"XML_Input_Param");

//Capture all XML Data using WebRegSaveParam
web_reg_save_param("ServerXML", "LB=", "RB=", "Search=body", LAST);


/*Send Custom Request - using XML from XML_Input_Param in which char variable data has been saved */
web_custom_request("SendXML",
"URL=https://10.10.xxx.xxx:8080/authService",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"Body={XML_Input_Param}",
LAST);

//Converted XPath verifications
lr_xml_find("XML={ServerXML}",
"Query=/CCAuthResponse/responseCode",
"Value=1",
LAST );
return 0;
}