Back to Blog

VuGen: Detailed Logging

The purpose of this VuGen code is so you have one place to enter the URL for the application and grab all the Load Generator and Controller information, and send it to the execution output logs for troubleshooting purposes. Variables are set at top of the action file that it can be changed by modifying one line of code instead of all the code within the script.

Put this code in the vuser_init() section of the script outside the vuser_init function

//*******************************************************************
//* GLOBAL VARIABLES USED IN ACTION FILES *
//*******************************************************************
//* 

int rc; // Global Variable for RC (result code of website response)
int ihttp; // Global Variable for HTTP Error Code returned by website

//Define Global Variables for Generator and Controller

char * generator_host;
char * controller_host;

// Global Variable For Application URL
//char *appurl = "app1.yourwebsite.com"; // Load Environment
 char *appurl = " app2.yourwebsite.com "; // System Environment

// Define Variables To Get Controller Information About Vusers and Groups
int id, scid; // Controllers And Scenarios
char *vuser_group; // Controllers And Scenarios
 //******************************************************************
 //* END - GLOBAL VARIABLES USED
 //*****************************************************************

Now here is what the vuser_init section INSIDE the vuser_init function would look like:

vuser_init()
 {
 //****************************************************
 //* START - This data is available for all functions *
 //****************************************************
 //Get The Name Of Generator and Controller In Server Farm
 generator_host = lr_get_host_name();
 controller_host = lr_get_master_host_name();
 // Get Information About VuserId, Group, Scenario Id
 lr_whoami( &id,&vuser_group,&scid );
 //********************************************
 //* END - Common Code For Each Action File *
 //********************************************
 return 0;
 }
ACTION()
 // ***********************************************
 // START - COMMON CODE USED AT TOP OF SCRIPT
 // ***********************************************
 // Global Variable For Business Process Name
 char *busprocessnm = "Name Of Business Process"; //Name Of Business Process Being Executed
 //Convert Global Parameter URL To Local Parameter
 lr_save_string( appurl,"pUrl" );
 // Convert Current Date/Time To Parameter To Be Used In Message Output
 lr_save_datetime( "%m/%d/%y-%X",DATE_NOW,"curdatetime" );
 // Display Current Date Only
 lr_save_datetime("%m/%d/%Y",DATE_NOW,"Currdate");
 // Clear Brower Cookies and Brower Cache
 web_cleanup_cookies();
 web_cache_cleanup();
 web_set_max_html_param_len("10000");
 // *********************************************
 // END - COMMON CODE USED AT TOP OF SCRIPT
 // *********************************************

Now you can start adding code within the action section around steps where you need more detailed logging:

1. This is the error trapping code for capturing web page failures. Let’s say you had a web form to fill out and you needed to check it. You would use the “rc=” in front of the step like this:

rc  = web_submit_data("search",
        "Action=http://www.yourwebsite.com/search",
        "Method=GET",
        "RecContentType=text/html",
        ITEMDATA,
        "name=q",
        "value=BeOS",
        ENDITEM,
        LAST);

and then use this error handling code after the step:

// ERROR TRAPPINGFOR HTTP STATUS ERRORS IN 400-500 RANGE
 if (rc == LR_FAIL)
 {
 ihttp = web_get_int_property(HTTP_INFO_RETURN_CODE);
 lr_error_message("INFO:>> It#:%s | BPName:%s | %s | Login Page Failed:
     %d | User: %s ",
     lr_eval_string("{Iteration}"),
     busprocessnm, lr_eval_string("{curdatetime}"), ihttp,
     lr_eval_string("{UserName}"));
 lr_output_message("INFO:>> It#:%s | BPName:%s | Login Page Failed: %d
      | User: %s ", lr_eval_string("{Iteration}"), busprocessnm,
      ihttp, lr_eval_string("{UserName}"));
 lr_end_transaction("TransactionName ", LR_FAIL);
 return 0;
 }
 lr_end_transaction("TransactionName", LR_AUTO);

2. This the code will displaying information about the LoadRunner server farm in the execution output log in Vugen.

lr_output_message(">> It#:%s | BPName:%s | Userid: %s | VuserID: %d |
     GroupName: %s | Controller: %s", lr_eval_string("{Iteration}"),
     busprocessnm, lr_eval_string("{UserName}"), vuser_group,
     lr_eval_string(lr_get_host_name()));
Back to Blog