Parameterize the object xpath in TruClient Protocol Loadrunner - JavaScript Based

Scenario:

1. Search a Company in the search field.
2. Click that Company from the search results.
3. Repeat Step 1 & 2 for different companies.


  • I searched for a company PERFORG60.
  • In the click step I found that the objects xpath had company name PERFORG60 and that is used to select that company.
  • Now I need to make the above steps work for different companies that I input.
  • Since the Company names are user inputs, I need to parameterize the Company name PERFORG60 in the xpath.

Steps:

1. Expand the Click Step --> Goto Objects --> JavaScript

2. Actual xpath generated in the step - evalXPath("//h3[text()=\"PERFORG60\"]");

3. Parameterized xpath to be replaced - evalXPath("//h3[text()=\""+ArgsContext.TC.getParam("P_OrgName")+"\"]");

where P_OrgName is the company name file parameter.



Now your script will click different company names which you input.

Parameterization in TruClient Protocol Loadrunner - JavaScript Based (Method 1 - TC.getParam)

Step 1 : Create a parameter under Parameters Dialog Box. I have created a File Parameter of name P_MPID. (Highlighted in RED)


Step 2 : Click the Develop Script button

Step 3 : Goto Tools --> Miscellaneous --> Evaluate JavaScript. Click and drag Evaluate JavaScript and place it above the step where the parameter P_MPID has to be passed. (Step Highlighted in BROWN - Last Image)



Step 4 : Fetch the parameters from P_MPID using TC.getParam function and assign it to the variable MPID. Follow the code in Arguments section. (Code Highlighted in RED)

Step 5 : Goto the step where the parameter P_MPID has to be passed and replace the original value with the variable MPID in Value field under Arguments section. (Highlighted in RED)

Step 6 : By default Value and Typing Intervals fields will be in Plain Text. Now click on the drop down arrow and select JavaScript <JS>. This has to be done because we are passing the parameter using JavaScript. (Highlighted in GREEN)



C Program (using strstr function) equivalent of web_reg_save_param in loadrunner.

I had a situtaion in which I was not able to retrieve the session id from the resposne using web_reg_save_param function. The session id was available in resposne header.
So what I did is, captured the entire response header and from that I retrieved the session id using the Left & Right boundary via C Program. Pls find the code below.

char *CStr; //variable in which the response header will be saved
char *LB = "SMSESSION="; //Left Boundary of Session ID
char *RB = "; path"; //Right Boundary of Session ID
char *CorrParam = NULL; //variable in which Session ID will be saved
char *start, *end;

web_save_header(RESPONSE, "Input"); //LR function to capture the response header

/* login request */
web_submit_data("login",

lr_output_message("# Response Header:\n %s", lr_eval_string("{Input}")); //Print the response header
 
    CStr = (char *)calloc(8000000,sizeof(char));
 
   strcpy(CStr, lr_eval_string(lr_eval_string("{Input}"))); //Save it to the C variable

    if ( start = (char *)strstr( CStr, LB ) ) //Finds the first occurance of LB in CStr
    {
        start += strlen( LB );
        if ( end = (char *)strstr( start, RB ) ) //Finds the first occurance of RB in CStr
        {
            CorrParam = ( char * )malloc( end - start + 1 );
            memcpy( CorrParam, start, end - start );
            CorrParam[end - start] = '\0';
        }
    }

    if ( CorrParam )
   
   // printf( "%s\n", CorrParam );
    lr_save_string(CorrParam,"CSMSESSIONID");
    lr_output_message("%s", lr_eval_string("{CSMSESSIONID}"));

    free( CorrParam );
 
    web_save_header(RESPONSE,"");

lr_save_float - C Program to convert Integer to Float in loadrunner

I have written a C program - user defined function to convert integer values to desired float decimal values in loadrunner.