Wednesday, March 3, 2010

Loadrunner - Good scripting guidelines.

Loadrunner - Good scripting guidelines.


1. Design your initial script in such a way that it works from the parameter list or fixed value (enter data into the script directly, especially used during debugging when user want to check with specific id's) and store the information into an variable for further use, I will explain it below.

Attaching sample code.


In the fixed value code, store data into a variable and convert into a parameter.

    /// Fixed value
    //sprintf(sUserName,"test@test.com"); 
    //lr_save_string(sUserName,"prmUserName");

    // OR 

In the parameter list code, store the data into variable.
    /// From the parameter list
    sprintf(sUserName,lr_eval_string("{prmUserName}")); <\code>

Enable or disable the code which ever is appropriate.

2. Response size, Log settings,  lr_output_message and lr_vuser_status_message
a) Measure response size of each request, this will give you idea about light and heavy pages.
b) Enable log when required dynamically through code, this will reduce the network activity between controller and load injector.
c) Use lr_output_message to store check point pass/fail status, login information, time stamps and dynamically generated acknowledgment numbers. Once test is completed, we can merge all the virtual user logs into a single file and compare values with the database or present failed check points along with the login information to the development team, so that it would be easy to tell which logins have failed while submitting the transactions.
Note: Need to write code in vbs to merge all the virtual user logs and generate report as required.
d) Use lr_vuser_status_message to display real time virtual user status in the virtual users window. Generally we see virtual users in "Running..' status during execution, we don't know in which page virtual user x is in the application. If your script is running for more than 30 minutes, real time virtual user information will help us to understand the health of your test and application.
Attaching screen shot displaying each virtual user login details and page activity information.
Place this function in important junctures, so that we can understand the real virtual user activity.

By looking at the above screen shot we can easily understand in which page our virtual users exist.

Attaching sample code for the above mentioned functions.

lDownloadSize = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );
lr_set_debug_message( LR_MSG_CLASS_BRIEF_LOG , LR_MSG_ON );
lr_output_message("%s | In Update Page...Bytes: %i",sUser,lDownloadSize);
lr_vuser_status_message("%s | In Update Page...Bytes: %i",sUser,lDownloadSize);
lr_set_debug_message( LR_MSG_CLASS_BRIEF_LOG , LR_MSG_OFF);
3. About lr_end_transaction

Create transactions to capture response time.
Consider following points while assigning LR_PASS to lr_end_transaction
a) Check transaction status.
b) Place checkpoints on conformation messages...
c) Size of response.
d) Transaction response time (Configured in SLA).

Attaching sample code

if (iStatus == LR_PASS || atoi(lr_eval_string("{UpdateSuccessful_count}")) == 1 || lDownloadSize > 5000) 
{
    lr_end_transaction("07_Update_Bid", LR_PASS);
}
else
{
    lr_end_transaction("07_Update_Bid", LR_FAIL);
}
Note: Assign numbers in ascending order to the transaction names, so that transactions will be arranged properly in the controller and analysis report.

4. Global think time

Think time is essential for emulating real scenarios, without it virtual users will be running at speed that is not true. It is very tedious to change the think time across the script.

Attaching sample code that will automate the process, change at one place will have effect across the script.
tips and tricks for configuration, scripting
and execution

int iThink_Time = 10;

lr_think_time(iThink_Time);
Create above variable as global variable by defining outside the vuser_int(), so that it can be accessed in all the actions


Loadrunner - Merging Virtual user log files.

Performance Testing - Validate server response.


HP loadrunner best practices, tips and tricks for configuration, scripting and execution






---

No comments:

Post a Comment