Perform the Same action multiple times with different parameters




Sometimes we might want to perform the same action multiple times with different parameters. The following is a basic example of how to do this in LoadRunner.
In this example we have three different Parameters {Param_1}, {Param_2} and {Param_3} as shown.




The following script will perform three searches on google.co.in using above three different parameters.

Action()
{
            int i;
            char temp[10];

            // Progress Through 3 Parameters stored in {Param_1}, {Param_2} and {Param_3}

            for(i=1;i<4;i++)
{

            //stores the output like {Param_1} to variable temp
                        sprintf(temp,"{Param_%d}",i );
//To print the value of temp
lr_message("print %s",temp );

//Evaluate the temp and store the value in Param_value
                        lr_save_string(lr_eval_string(temp), "Param_value");

                        lr_start_transaction("Search");

//To print the value in Param_value               
                        lr_output_message("Parameter is %s", lr_eval_string("{Param_value}"));

                        // To find the value in Number of Results
                        web_reg_save_param("Number_of_Results", "LB=About ", "RB= results", LAST);

                        // Validate Content
                        web_reg_find("Text=<title>{Param_value} - Google Search</title>", LAST);

                        web_url("search",
                        "URL=http://www.google.co.in/search?hl=en&q={Param_value}",
                        "Resource=0",
                        "RecContentType=text/html",
                        "Referer=http://www.google.co.in/",
                        "Snapshot=t20.inf",
                        "Mode=HTML",
                        LAST);

                        lr_output_message("Results is %s", lr_eval_string("{Number_of_Results}"));

                        lr_end_transaction("Search", LR_AUTO);
            }
            return 0;
}


Output:

Virtual User Script started at : 2013-03-22 13:21:22
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31)          [MsgId: MMSG-27143]
Run Mode: HTML      [MsgId: MMSG-26000]
Run-Time Settings file: "XXXX\noname1\\default.cfg"        [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
print {Param_1}
Action.c(20): Notify: Transaction "Search" started.
Action.c(23): Parameter is India
Action.c(26): Registering web_reg_save_param was successful        [MsgId: MMSG-26390]
Action.c(29): Registering web_reg_find was successful        [MsgId: MMSG-26390]
Action.c(31): Redirecting "http://www.google.co.in/search?hl=en&q=India" (redirection depth is 0)         [MsgId: MMSG-26694]
Action.c(31): To location "http://www.google.co.in/search?hl=en&q=India&safe=active"              [MsgId: MMSG-26693]
Action.c(31): Found resource "http://news.google.co.in/news/tbn/D0A9oUzHSLEJ/6.jpg" in HTML "http://www.google.co.in/search?hl=en&q=India&safe=active"       [MsgId: MMSG-26659]
Action.c(31): Found resource "http://www.google.co.in/maps/vt/data=Ay5GWBeob_WIPLDYoIWcfVXxvZu9XwJ55OX7Ag,9VaQjlC087k_75mFRH9mowSvvHJB_dkxhpdX6M2vqKE81Kf7OTZ0ZwAZ4lr7FRR8LKCgWhktbnWGJcnf5_doEDTc_-md8XA" in HTML "http://www.google.co.in/search?hl=en&q=India&safe=active"           [MsgId: MMSG-26659]
Action.c(31): Registered web_reg_find successful for "Text=<title>India - Google Search</title>" (count=1)              [MsgId: MMSG-26364]
Action.c(31): web_url("search") was successful, 69715 body bytes, 1850 header bytes       [MsgId: MMSG-26386]
Action.c(40): Results is 553,000,000
Action.c(42): Notify: Transaction "Search" ended with "Pass" status (Duration: 3.0071 Wasted Time: 0.9922).
print {Param_2}
Action.c(20): Notify: Transaction "Search" started.
Action.c(23): Parameter is Day
Action.c(26): Registering web_reg_save_param was successful        [MsgId: MMSG-26390]
Action.c(29): Registering web_reg_find was successful        [MsgId: MMSG-26390]
Action.c(31): Redirecting "http://www.google.co.in/search?hl=en&q=Day" (redirection depth is 0)           [MsgId: MMSG-26694]
Action.c(31): To location "http://www.google.co.in/search?hl=en&q=Day&safe=active"    [MsgId: MMSG-26693]
Action.c(31): Registered web_reg_find successful for "Text=<title>Day - Google Search</title>" (count=1)              [MsgId: MMSG-26364]
Action.c(31): web_url("search") was successful, 54179 body bytes, 702 header bytes         [MsgId: MMSG-26386]
Action.c(40): Results is 2,020,000,000
Action.c(42): Notify: Transaction "Search" ended with "Pass" status (Duration: 1.3367 Wasted Time: 0.0303).
And so on…

Comments

  1. Dear friend. I truly just like your posting and your current web page all in all! That write-up is really plainly composed and without difficulty understandable. Your Wordpress style is awesome as well! Would be awesome to discover exactly where My partner and i are able obtain this. Please hold up the very good work. We all need much more this kind of website owners just like you on the web and much less spammers. Wonderful man!


    http://www.sqlservermasters.com/

    ReplyDelete
  2. belniZcrem-chi Matthew Matondang Download
    llevconsbedgung

    ReplyDelete
  3. seccomPdeka-1979 Jeff Edwards Here
    castholrame

    ReplyDelete

Post a Comment

Popular posts from this blog

Steps to Analyze AWR Report in Oracle

Vmstat Output explained

Verifications and Error Handling in LoadRunner *Web_reg_find and Web_reg_save_param*