Testing is Rocket Science Not Brain Surgery

Almost all of the World's Greatest Accomplishments Were The Result of Great Planning!

Testing is Rocket Science Not Brain Surgery header image 2

Code Snippets(HP LoadRunner): Randomly Selecting an Array of Values and Using That Value As A Parameter by Howard Clark

February 6th, 2008 · 3 Comments · Code Snippets

Table of contents for Code Snippets(HP LoadRunner)

  1. Code Snippets(HP LoadRunner): Randomly Selecting an Array of Values and Using That Value As A Parameter by Howard Clark
  2. Code Snippets(HP LoadRunner): Decrypting Passwords and Using those Values in a web_submit statement by Howard Clark
  3. Code Snippet(HP LoadRunner) : FILE I/O and creating dummy XMLs

int TotalNumberOfBUIDs;
char TotalNumberOfBUIDschar[3]; //working variable
char *AvailableBUIDsparam; //working variable

web_reg_save_param(“AvailableBUIDs”,
“LB/IC=class=’PSSRCHRESULTSODDROW’ >”,
“RB/IC=”,
“Ord=All”,
“Search=Body”,
“RelFrameId=1”,
“Notfound=error”,
LAST);

TotalNumberOfBUIDs=atoi(lr_eval_string(“{AvailableBUIDs_count}”));
TotalNumberOfBUIDs = rand() %TotalNumberOfBUIDs;
lr_output_message(“%d”, TotalNumberOfBUIDs);
itoa(TotalNumberOfBUIDs, TotalNumberOfBUIDschar, 10); //working variable conversion

lr_save_string(TotalNumberOfBUIDschar, “BUIDindex”);
AvailableBUIDsparam = lr_eval_string(“{AvailableBUIDs_{BUIDindex}}”);
lr_save_string(AvailableBUIDsparam, “BUIDs”);
lr_save_string((lr_eval_string(lr_eval_string(“{BUIDs}”))), “BUID”);

“Name=VCHR_ERRC_WRK_BUSINESS_UNIT”, “Value={BUID}”, ENDITEM, //application of the value that was captured and then randomized

The AUT is Peoplesoft Financials 9.0 using the HTTP/HTML protocol implemented in C.

The idea is to take a list of values that were retrieved as a set of search results, and randomly select one of those search result values. There would also be a check as to whether that value was blank or not depending on your needs. I typically implement a “no results found” check in the content check rules in LoadRunner to make them more maintainable versus a bunch of exception handling, a virtue of working with text streams and LR’s built in text parsing capabilities.

Tags: ··········

3 Comments so far ↓

  • Basavaiah

    Hi looks really good,

    Tried using this code, But recieved runtime error saying

    arthemetic error : exception int_devide_by_zero received

    Here I am confused, is the BUIDs is the parameter name?
    I am working on the PS 9.0.

    my search returns few rows, in each iteration I need to work on different row. In results page i am seeing only 10 results even thow there were 120. i need to click next to see the following records.

    so how would i do arraying, in my scenario

  • Administrator

    First, the BUIDs variable is the value that is put into the BUID parameter.

    Second, the exception you are receiving is from my effort to get a record in the array randomly.
    If this statement is a zero value:
    TotalNumberOfBUIDs=atoi(lr_eval_string(”{AvailableBUIDs_count}”));
    then it will not work here:
    TotalNumberOfBUIDs = rand() %TotalNumberOfBUIDs;

    If you can use a filter on your results then you could increment through 10 records at a time and apply your filter settings to get the next 10 records reusing the same parameter for a fresh set of records.

    Unfortunately I don’t see any way around you having to simulate a multi-dimensional array by managing a collection of parameters for each page of results. So you would increment your paramater name by one with each webpage submit of the next page link. Once you have your parameter of arrays built you would then step through them, and then move on to the next parameter array.

  • sandra407

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

Leave a Comment