Sunday, March 1, 2015

L.R_File Operations_01



Action()
{
    char *filename = "D:\\sundar\\From_LR\\Cntrl_Otpt_29th.txt";
    long file;
                char *groupname;
                int id,m,n;
    web_save_timestamp_param( "tmstampParam", LAST );
                lr_output_message(lr_eval_string("{tmstampParam}"));
                m=rand()%41+20;
     n=atoi(lr_eval_string("{VID}"));
                lr_output_message("%d",n);
     // Create a new file
                file = fopen(filename, "a+" );
                fprintf(file, "Random number is: %d and                               Vuser Number is:  %d \n",m,n);
  // Write the Vuser ID and group to the log file
     lr_whoami(&id, &groupname, NULL);

    fprintf(file, "log file of virtual user ID: %d                          group: %s\n \n", id, groupname);
    fclose(file);
lr_think_time(10);
return 0;
}

/*  Output – S.S.Reddy   */
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(9): Notify: Saving Parameter "tmstampParam = 1425195876184".
Action.c(9): web_save_timestamp_param("web_save_timestamp_param") was successful       [MsgId: MMSG-26392]
Action.c(10): Notify: Parameter Substitution: parameter "tmstampParam" =  "1425195876184"
Action.c(10): 1425195876184
Action.c(15): Notify: Parameter Substitution: parameter "VID" =  "1"
Action.c(17): 1
Action.c(35): lr_think_time: 13.82 seconds (recorded think time was 10.00 seconds).
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Starting action Action.
Action.c(9): Notify: Saving Parameter "tmstampParam = 1425195890319".
Action.c(9): web_save_timestamp_param("web_save_timestamp_param") was successful       [MsgId: MMSG-26392]
Action.c(10): Notify: Parameter Substitution: parameter "tmstampParam" =  "1425195890319"
Action.c(10): 1425195890319
Action.c(15): Notify: Parameter Substitution: parameter "VID" =  "1"
Action.c(17): 1
Action.c(35): lr_think_time: 13.13 seconds (recorded think time was 10.00 seconds).
Ending action Action.
Ending iteration 2.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

/*   Below is the Result in Output File—Notepad   */
Random number is: 47 and                          Vuser Number is:  1
log file of virtual user ID:  1                          group: None

Random number is: 21 and                          Vuser Number is:  2
log file of virtual user ID:  2                          group: None


 


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

L.R._File Operations-Sample



Action()
{
    char *filename = "D:\\sundar\\From_LR\\cntr_wid_date_112.txt";
    long file;
                char *groupname;
                int id,m,n;
                m=rand()%21+20;
    n=atoi(lr_eval_string("{VID}"));
                lr_output_message("Vuser ID is: %d",n);
                lr_save_datetime("%y%m%d", DATE_NOW, "FileDate");
                lr_save_datetime("%y/%m/%d", DATE_NOW, "Date");
                lr_save_datetime("%H:%M", TIME_NOW, "Time");
// Create a new file
                file = fopen(filename, "a+" );
fprintf(file, "Random number is: %d and Vuser Number is:  %d \n and today is: %s, at %s on %s. \r\n",m,n,
     lr_eval_string("{FileDate}"), lr_eval_string("{Time}"), lr_eval_string("{Date}"));

// Write the Vuser ID and group to the log file
    lr_whoami(&id, &groupname, NULL);
    fprintf(file, "log file of virtual user ID: %d group: %s\n", id, groupname);
/*  lr_save_datetime("%y%m%d", DATE_NOW, "FileDate");
      lr_save_datetime("%y/%m/%d", DATE_NOW, "Date");
       lr_save_datetime("%H:%M", TIME_NOW, "Time");

// Write the Vuser ID and group to the log file
                                sprintf(OutputFile,"D:\\sundar\\From_LR\\output_33_2.txt", lr_eval_string("{FileDate}"),
                lr_eval_string("{Iteration}"),
                lr_eval_string("{Time}"),
                lr_eval_string("{Date}"));
                lr_whoami(&id, &groupname, NULL);
    fprintf(file, "log file of virtual user ID: %d group: %s\n", id, groupname);   */
    fclose(file);
    lr_think_time(10);
return 0;
}



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

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.