Sample LoadRunner Script ( 2002 Mercury Interactive Corporation)


In Chapter 7, we included subsets of a Pet Store test script as examples. This section contains the complete scripts for the application. [5] Warning: We do not recommend Pet Store as a performance benchmark application for running under load conditions. We provide these scripts merely as examples for building your own test scripts, but we do not recommend that you use them for actual performance testing.

[5] Profuse thanks to Leo Cai for his work on this sample script.

LoadRunner Initialization Section

 #include "as_web.h" #include "lrw_custom_body.h" /* This is a LoadRunner sample script using LoadRunner 7.02 against a IBM    WebSphere Advanced Edition running Sun's Pet Store Sample Application.    We emulate the shopping activity of a store visitor. First the visitor    logs in to the store (in the vuser_init session), then the visitor    browses through the store for different pets (in the Action1 session),    finally the visitor proceeds to finish the check out procedure and then    log out (in the vuser_end session).    Make sure that you go to the parameter file to add the user ID to log    in to the pet store! */ vuser_init() { /* type in the Pet Store url:   */   web_url("main",      "URL=http://localhost/estore/control/main",      "TargetFrame=",      "Resource=0",      "RecContentType=text/html",      "Referer=",      "Snapshot=t1.inf",      "Mode=HTML",      LAST);  lr_think_time( 2 );  web_image("sign-in.gif",     "Src=/estore/images/sign-in.gif",     "Snapshot=t2.inf",     LAST);  lr_think_time( 9 );  /* Sign in to the pet store. */  lr_think_time( 2 );  web_submit_form("verifysignin",     "Snapshot=t3.inf",     ITEMDATA,     "Name=j_username", "Value={userid}", ENDITEM,     "Name=j_password", "Value={Passwd}", ENDITEM,     "Name=submit.x", "Value=29", ENDITEM,     "Name=submit.y", "Value=6", ENDITEM,     LAST);  lr_think_time( 2 );  /* Click on store main page   */ web_link("Store Main Page",   "Text=Store Main Page",   "Snapshot=t4.inf",   LAST);  return 0; 

LoadRunner Action1 Section

 #include "as_web.h" /* This is the section where the visitor will browse through the pet store    and add the pets to the shopping cart. */ int i,j, Count;// declare the integer used in the script char Param[256];// declare a character string used in the script char Link[256];// declare a second character string used in the script Action1() {    /* Click on main page. */    lr_think_time( 2 );    /* The following statement captures the array of pet categories and        saves them as pet_1, pet_2, etc. */   web_reg_save_param("pet","LB=images/nav-", "RB=.gif\"","Search=body","Ord=all",LAST);    /* Visit first level of pet store.  */    web_url("main",       "URL=http://localhost/estore/control/main",       "TargetFrame=",       "Resource=0",       "RecContentType=text/html",       "Referer=",       "Snapshot=t1.inf",       "Mode=HTML",       LAST);    { /* The following statement saves the total number of pet counts to an    integer Count */       Count = atoi(lr_eval_string("{pet_count}")); /* The following statement does three tasks:    1. LoadRunner randomly picks a number defined by Num (you can change    the range from the parameter list. It defaults from 1 to 10000) and    then Num is modulized by Count. Since the web page numbering starts    from 1 instead of 0, a 1 is added to the modulized result. Please refer    to C programming language documentation for an explanation of the modu-    lus operator.    2. After a number is randomly picked, the pet category is determined by    pet_1, etc.,    3. the category is then assigned to a character string called Param */      sprintf(Param,"{pet_%d}",atoi(lr_eval_string("{Num}")) % Count + 1); /* The following statement constructs a string that can be used in a    LoadRunner function statement. For example, if pet_1=cat is picked    from the previous statement, then Link will be assigned    "Src=/estore/images/nav-cat.gif" */      sprintf(Link,"Src=/estore/images/nav-%s.gif",lr_eval_string(Param));    } /* The following statement will capture the subcategories of the pet store    and save them as sub_pet_1, sub_pet_2, etc. */   web_reg_save_param("sub_pet","LB=\">\n ","RB=\n\t </a>","Search=body","Ord=all",LAST); /* This statement will simulate a click on any of the categories dictated    by Link */   web_image("The first link: species",   Link,   "Snapshot=t2.inf",   LAST);  { /* The following statement saves the total number of subcategories to an    integer Count*/      Count = atoi(lr_eval_string("{sub_pet_count}")); /* Similar to previous sprintf statement, this statement will accomplish 3    tasks again:    LoadRunner randomly picks a number between 1 to 10000 and modulized by    the total number of counts (plus 1) and then    assigns the random number to sub_pet_(number) so that Param will be    assigned sub_pet_1.    sub_pet_2, etc. sub_pet_1, etc. is captured in the web_image ( )    LoadRunner function statement. */      sprintf(Param,"{sub_pet_%d}",atoi(lr_eval_string("{Num}")) % Count + 1); /* The following statement will construct the string Link to be used in    the subsequent LoadRunner function statement. For example, Link repre-    sents "Text=Bulldog */      sprintf(Link,"Text=%s",lr_eval_string(Param));  } /* The following statement simulates a click on one of the sub catego-    ries. */    web_reg_save_param("sub_pet2","LB=\">\n ","RB=</a>","Search=body","Ord=all",LAST);    web_link("The second link: sub categories",      Link,      "Snapshot=t3.inf",      LAST);    { /* The following statement saves the total number of sub_pet2 categories    to an integer Count */      Count = atoi(lr_eval_string("{sub_pet2_count}")); /* Similar to previous sprintf statement, this statement will accomplish 3    tasks again:    LoadRunner randomly picks a number between 1 to 10000 and modularized    by the total number of counts (plus 1)    and then assigns the random number to sub_pet_(number) so that Param    will be assigned sub_pet_1.    sub_pet_2, etc. sub_pet_1, etc. is captured in the web_image ( )    LoadRunner function statement. */      sprintf(Param,"{sub_pet2_%d}",atoi(lr_eval_string("{Num}")) % Count + 1); /* The following statement will construct the string Link to be used in    the subsequent LoadRunner function statement. For example, Link repre-    sents "Text=Bulldog */      sprintf(Link,"Text=%s",lr_eval_string(Param));    } /* The following statement makes a click on the third page of the    pet site */    lr_think_time( 2 );    web_link("The third link: specific pet",      Link,      "Snapshot=t4.inf",      LAST);    lr_think_time( 2 );    /* click to add pet to the shopping cart. */    web_image("Add Item to Your Shopping Cart",      "Alt=Add Item to Your Shopping Cart",      "Snapshot=t8.inf",      LAST);  lr_think_time( 2 );  return 0; 

LoadRunner End Section

 #include "as_web.h" vuser_end() { /* This is the section where the visitor has finished browsing the pet    store and is getting ready to check out and leave the pet store. */   web_url("checkout",      "URL=http://localhost/estore/control/checkout",      "TargetFrame=",      "Resource=0",      "RecContentType=text/html",      "Referer=http://localhost/estore/control/cart?action=      //updateCart&itemQuantity_EST-1=1&update.x=33&update.y=8",      "Snapshot=t10.inf",      "Mode=HTML",      LAST);   web_image("Continue",      "Alt=Continue",      "Snapshot=t11.inf",      LAST);   lr_think_time( 2 );   lr_start_transaction("Process_payment");   lr_think_time( 2 );   web_submit_form("validatebillinginformation",      "Snapshot=t12.inf",      ITEMDATA,      "Name=credit_card_type", "Value=Visa", ENDITEM,      "Name=credit_card_number", "Value=9999 9999 9999 9999", ENDITEM,      "Name=expiration_month", "Value=01", ENDITEM,      "Name=expiration_year", "Value=2001", ENDITEM,      "Name=given_name", "Value=Cai", ENDITEM,      "Name=family_name", "Value=Leo", ENDITEM,      "Name=address_1", "Value=1325 Borregas Ave", ENDITEM,      "Name=address_2", "Value=", ENDITEM,      "Name=city", "Value=Sunnyvale", ENDITEM,      "Name=state_or_province", "Value=California", ENDITEM,      "Name=postal_code", "Value=94089", ENDITEM,      "Name=country", "Value=USA", ENDITEM,      "Name=telephone_number", "Value=408-822-5737", ENDITEM,      "Name=ship_to_billing_address", "Value=on", ENDITEM,      "Name=x", "Value=66", ENDITEM,      "Name=y", "Value=9", ENDITEM,      LAST);   lr_end_transaction("Process_payment", LR_AUTO);   lr_think_time( 3 );   /* Now it is time to leave the store! */   lr_think_time( 3 );   web_image("sign-out.gif",     "Src=/estore/images/sign-out.gif",     "Snapshot=t13.inf",     LAST);     return 0; 


Performance Analysis for Java Web Sites
Performance Analysis for Javaв„ў Websites
ISBN: 0201844540
EAN: 2147483647
Year: 2001
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net