Wednesday, August 17, 2011

LoadRunner 11 - Adding a Plugin to TrueClient Firefox browser

LoadRunner 11 comes with a new protocol called TruClient. It records a business process using the Firefox browser. By default, the browser does not come with plugins such as Firebug. However, you can still add a Firefox plugin and use it while using TruClient during scripting process. For demonstration purpose, I will show you how to add "Firebug" plugin to the TruClient browser and the steps are as follows:

1: Select the TruClient protocol and then click Tools -> Ajax TruClient Browser Configuration option. An "Ajax TruClient Browser Configuration" popup window is displayed.

2: Click on "Extensions" tab. All existing plugin list will be displayed. See the screenshot below.

3: Click on "Get Add-Ons" button. All the recommended plugin list is displayed.

4: Type in "Firebug" in the search textbox and click "Search" icon. A result list is displayed. Incase you do not see the "Firebug" plugin, click on "See all results..." link. This will bring up the list of all the plugins in a browser.

5: Click on "Add to Firefox" button next to the Firebug plugin and follow all the necessary steps. Once the Firebug is installed. Restart the Firefox browser.

6: If the browser is open, close the browser and click "Develop Script" button in VUGen. This will open up a Firefox browser. At the bottom right corner of the browser, you will now see a firebug icon. Firebug plugin is now ready to be used while you are recording a script using TruClient protocol.

Tuesday, August 16, 2011

LoadRunner - Converting Number Into Currency(/Dollar)

Couple of times when scripting a business process, I have come across situations where I needed to submit a dollar amount. For example, I would type in a number 12345 in a textbox and the application would convert it into $12,345 before submitting the request. There are three ways to solve this problem and they are:

1: Hard code the dollar value in the request. I wouldn't suggest doing it this way. However, there might be situations where it might be OK to hard code the value.

2: Save dollar values in a text file and then use a LR parameter for your requests.

3: Another way is to write a C function which converts a number into a dollar(/currency) value, which you can later assign to an LR parameter. The code is as below:

char *ConvertStringToCurrency(char string[20])
{ 
char *tempResult; //temporary result variable
int counter;
int i=0;
tempResult= (char *)malloc(sizeof(string)+10); //dynamically allocate memory for variable tempResultmake sure there is enough space for extra characters that will be added.

strcpy(tempResult,"$");

for(counter=0;counter<strlen(string);counter++)
{   
if((strlen(string)-counter)%3==0 && counter!=0) //insert a comma every third character  and not at the start.
{
tempResult[++i]=',';
}
tempResult[++i]=string[counter];
}
tempResult[++i]='\0';

return tempResult;   //return final currency
}

Action()
{
    char *tempCurrency;

 tempCurrency = (char *)malloc(sizeof(lr_eval_string ("{NonCurString}"))); //dynamically create the size of tempCurrency var based on size of NonCurString parameter

 sprintf(tempCurrency,"%s",lr_eval_string ("{NonCurString}")); //save NonCurString paramater value in to tempCurrency var

 lr_output_message ("Before Conversion %s",tempCurrency); //output the currency value before conversion

 sprintf(tempCurrency,"%s",ConvertStringToCurrency(tempCurrency));  //save the new value into tempCurrency 

 lr_save_string (tempCurrency,"Currency"); //save the tempCurrency value into parameter called Currency

 lr_output_message ("After Conversion %s",lr_eval_string ("{Currency}")); // output the Currency value

 return 0;
}

You will require to update the above code incase the final value is bigger than 20 characters. My code assumes the inital number is not bigger than 10 characters. This allows me to assign the final value back to variable "tempCurrency".

NOTE: Make sure you are freeing the memory. This code does not free the memory as I have left it for you to add that code.

Following is a screenshot of the final result when the above code is executed in LoadRunner.




How To Access(& Monitoring) Apache Server Counters

The Apache server comes with different counters which allows you to monitor the health of the server. When extended status is enabled you can not only access default counters but also the following counters. They are:

Extended Status ON
*Total Accesses - Total access count since the server was started
*Total kBytes - Total volume delivered in bytes since the server was started
*Uptime - Time during which the server was running
*ReqPerSec - Average number of requests per second since the server was started
*BytesPerSec - Average number of bytes delivered per second
*BytesPerReq - Average number of bytes per request
*CPULoad - not available on most Win32 versions

Default Counters
*BusyWorkers - Number of worker processes actively processing requests
*IdleWorkers - Number of worker processes idle

How To Access The Apache Counters
The following steps are based on Apache 2.2 version (it was installed as part of XAMPP application). Also I am running the server on my local machine.

1: Open up the httpd.conf file. If installed via XAMPP, this file is found in the "conf" folder in the main "Apache" folder.
2: Search for "status_module" module and remove "#" tag infront of LoadModule text, incase it exists. Change "#LoadModule status_module modules/mod_status.so" to "LoadModule status_module modules/mod_status.so". See the screenshot below.
3: Restart the Apache Server for server to pick up the changes made to conf file.
4: Navigate to "http://localhost/server-status?auto" URL. Now you should be able to monitor the default counters(see the screenshot below). If the server is running on a remote machine then the URL will be "http://servername:port/server-status?auto".

To get further Apache counters, perform the following actions:
5: Add "ExtendedStatus On" text at the bottom of the httpd.conf file. See the screenshot below.
6: Restart the Apache Server for server to pick up the changes made to conf file.
7: Navigate to "http://localhost/server-status?auto" URL. Now you should be able to view the default counters as well as the extended counters(see the screenshot below).

If you want further information such as "PID", "DNS Lookup", "Waiting for Connection", "Reading Request", Server Version etc, then just navigate to the following URL ("http://localhost/server-status") on your localhost or "http://servername:port/server-status" for remote server. See the screenshot below.



NOTE: By default ExtendedStatus is not enabled. When enabled it will make multiple time calls and this can cause a performance hit.

NOTE:Once you have enabled the status, you can access these counters via the HP SiteScope application.