Back to Blog

VuGen Error Checking and Detailed Logging

This is a basic scripting technique for enhancing your VuGen scripts to add error checking and detailed logging (in this case a web HTTP status code that is in the 4XX – 5XX range) for specific steps.

First, set up a parameter called {pIteration} that uses the Iteration Number type to automatically keep track of the iteration. At the beginning of my action.c I might start with something like this:

// Declare Variables
int rc = 0, iHttp;
lr_vuser_status_message("Starting iteration Number: %s",
     lr_eval_string({pIteration}));
web_cache_cleanup();  
web_cleanup_cookies();

I would only include the last two lines there if we were running the action over and over and there was a chance of getting kicked out and starting over at the action without having the existing cache and cookies cleared. You may not need these.

I use the rc and iHttp variables for error checking specific steps, such as web form submissions, or other critical pages. I then send a message to the controller so I can pull up the Vusers window and see what iteration each on is on. I clean the cache and cookies at the beginning and end of each step even though I have the proper run time settings checked. I use the rc and iHttp variable with error checking because I check the option to continue on error. I control the exit of the script when my “if” condition runs. This is an example of error checking that would tell you more than you would get by default in the execution log:

// Step to check for errors
rc = web_submit_data("Search",....blah...blah...blah);

//error checking

if (rc == LR_FAIL)
 {
 iHttp = web_get_int_property( HTTP_INFO_RETURN_CODE );
 lr_error_message("HTTP return code was: %d", iHttp);
 lr_vuser_status_message ("Search page failed for %s, iteration: %s",
     lr_eval_string("{pLogin}"), lr_eval_string("{pIteration}"));
 lr_error_message ("Search page failed for %s, iteration: %s",
     lr_eval_string("{pLogin}"), lr_eval_string("{pIteration}"));
 return 0;
 };

I get the http property and log it to the output execution log, but  I send that same message to the log that can be displayed in the controller, so that this specific step (in this case, Search) failed within the scenario without having to open the execution log in Vugen. It also tells me the iteration number. This may help me understand if I have just a couple of bad data values or a bigger issue when a failure occurs. Notice at the end of the message, I am including the name of the user from the parameter file. I generally use {pLogin} as the login id from a parameter file when using a different user for each iteration.

Do you have other logging techniques? Feel free to comment below.

Back to Blog