Sunday, March 1, 2015

Load Runner - Functions_v0.1


Action()
{
    /*      Shyam S.Reddy ---- 2015    */

    lr_message("text");  //
    lr_output_message("Ttext");         //To print an output message
    lr_error_message("text");               // To print error message (Error message will be in red)
    lr_save_string("text1","text2");     // To replace text2 with text1

 /*     Find the current iteration Number is::  First create a "Parameter List-->>New-->> Parametertype=iteration number-->>specify text format ->  01, 001, 0002    */


  lr_output_message("Current iteration number is:   %s", lr_eval_string("{Iterat_NoPRM}"));
  Output is:: Action.c(11): Notify: Parameter Substitution: parameter "Iterat_NoPRM" =  "01"
        Action.c(11): Current iteration number is:   01
        (02, 03, 04,...... based No. of iterations specified in "Run Logic")

    lr_start_transaction("SSR_Login_HomePage");
/*  startig transacations bla bla....  */
    lr_end_transaction("SSR_Login_HomePage", LR_AUTO);

    web_reg_save_param("Name","LB=","RB=","ORD=",LAST); //Correlation
    depcity=lr_paramarr_random("Cities"); //Storing "Cities" randomly in a C variable
    city:
    arrcity=lr_paramarr_random("Cities"); //Storing "Cities" in a C variable
        if(strcmp(depcity,arrcity)==0) // If statement
        {
        goto city;
        }
    lr_save_string(depcity,"Depcity"); //Saving Loadrunner variable
    lr_save_string(arrcity,"Arrcity");

    lr_output_message("Travelling from %s") //Printing out message in LR

    temp=lr_paramarr_idx("OFlight",1); //Picking "OFlight" value randomly and Storing in a C variable
    token=(char*)strtok(temp," ");  //strtok returns a token from a string delimited by specified characters.

    lr_save_string(token,"OFlight_1");     //_1 is to replace the first value

    i=rand()%4+1;
    oflight=lr_paramarr_idx("OFlight",i);
    lr_save_string(oflight,"flight");

    Char *text  //Defining Character
    int i;  //Defining Integers

    web_reg_find("Text=Web Tours", "SaveCount=test1",
        LAST)   // To save the count of Text occurance

/*   Array Merging   - SSR */
    int i,l,m,x,y,z;
    char *depcity,*arrcity,*seatpref,*seattype,*temp,*token,*oflight;

    l=lr_paramarr_len("Cities");
    m=lr_paramarr_len("city");

    for(x=1;x<=m;x++)
    {    temp=lr_paramarr_idx("city",x);
        lr_save_int(l+x,"int");
        lr_save_string(temp,lr_eval_string("Cities_{int}"));
    }
        y=rand()%20+1;
    depcity=lr_paramarr_idx("Cities",y);
city:
    z=rand()%20+1;
    arrcity=lr_paramarr_idx("Cities",z);

    if(strcmp(depcity,arrcity)==0)
    {
        goto city;
    }
    lr_save_string(depcity,"Depcity");
    lr_save_string(arrcity,"Arrcity");
    //lr_output_message("Travelling from %s")

    seatpref=lr_paramarr_random("SeatPerf");
    lr_save_string(seatpref,"SPref");

    seattype=lr_paramarr_random("SeatType");
    lr_save_string(seattype,"SType");    /*  Array merging ended SSR */

   i=web_get_int_property(HTTP_INFO_RETURN_CODE); // To save the responce code of the web page (Used in Error handling)
    i=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); // To save the size of downloaded file
    i=web_get_int_property(HTTP_INFO_DOWNLOAD_TIME); // To save the
    i=web_get_int_property(HTTP_INFO_TOTAL_REQUEST_STAT); // Returns the accumulated size of all headers and bodies since the first time web_get_int_property was issued 
    i=web_get_int_property(HTTP_INFO_TOTAL_RESPONSE_STAT); // Returns the accumulated size, including header and body, of all responses since the first time web_get_int_property

    LR_EXIT_VUSER // Exit without any condition, and go directly to end action
    LR_EXIT_ACTION_AND_CONTINUE  //Stop current action, and go to the next action.
    lr_exit(LR_EXIT_MAIN_ITERATION_AND_CONTINUE,LR_FAIL);
return 0;
}
                        /*      Shyam S.Reddy ---- 2015    */

 

Note: Some of the articles are grab from various Websites / Blogs.

No comments:

Post a Comment