Tuesday, 8 April 2014

Load Runner code for writing data in notepad


Below code is to save the Vendor numbers to a notepad.
(put it in vuserinit starting after Header)
//Path for saving the notepad file, the file name is "MatDocument.txt"

#define filename "C:\\Documents and Settings\\ravi\\Desktop\\MatDocument.txt"

f_Write(char *str1)
{
          long a;
          a = fopen(filename,"a+");
          if (a==NULL)
           {
             return -1;
          }
          else
          {
             fprintf(a,"Material Document Number is %s\n",str1);
             fclose(a);
          }
}



Save a parameter in notepad file:

This code will create a notepad file and save the parameter into it.


long fd;
web_reg_save_param("saveID","LB=---","RB=---","ORD=1",Last); //Capture the value in "saveID"
fd=fopen( "C:\\NotepadName.txt","a" ); //Path of notepad
fprintf( fd,"%s\n",lr_eval_string("{saveID"})); //It will print the data and go to next line
fclose( fd ); // It will close notepad.

How to find out Memory Leak in an application?

How to find out Memory Leak in an application?

There are many reasons for memory leak and being a tester its tough to find exact reason. The basic thing we need to understand what is memory leak? How it occurs?
Memory leak can be defined as the un-allocated space in a system which was used by a program and after  use it was never returned to the operating system. This un-allocated (unused memory) can cause shortage of memory and may crash the entire system.

There are few steps which may help to find out memory leak in  a system:
  1. We can monitor the memory graph by using perfmon and check if the memory utilization is keep on increasing and remain at peak even without any load, it shows the memory that was used while executing the program is still in use even the program doesn't needs it. The un-managed code is not efficient enough to release the memory and free it after use, which may cause out of memory issue.
  2. You can check the throughput graph while load testing and if there is sudden spike in it then it can be one of the reason for memory leak. But we can't assure the spike in graph is because of memory leak, the other reason could be due to network traffic, data base connectivity issue etc.
  3. We have GC to collect all the un-allocated space and return it to system, it has some limitations:
  • In a manually managed memory environment: Memory is dynamically allocated and referenced by a pointer. The pointer is erased before the memory is freed. After the pointer is erased, the memory can no longer be accessed and therefore cannot be freed.
  • In a dynamically managed memory environment: Memory is disposed of but never collected, because a reference to the object is still active. Because a reference to the object is still active, the garbage collector never collects that memory. This can occur with a reference that is set by the system or the program.
  • In a dynamically managed memory environment: The garbage collector can collect and free the memory but never returns it to the operating system. This occurs when the garbage collector cannot move the objects that are still in use to one portion of the memory and free the rest.
  • In any memory environment: Poor memory management can result when many large objects are declared and never permitted to leave scope. As a result, memory is used and never freed.

How do we write a user defined function in LoadRunner?

How do we write a user defined function in LoadRunner?

Create the external library that contains the function. This library must then be added to the bin directory of VuGen. And then, the user-defined function can be assigned as a parameter.

-Source-Internet:

We need to create an external DLL libraray to use the user defiend function. It can be substitued as paramter values.

The syntax is:
__declspec(dllexport) char *(char *, char *)
Both the arguments passed are NULL for this function.

An User-defined function could be :
__declspec(dllexport) char *GetSysDate(char *, char *)

This would return the system date. You could substitute this returned value for a parameter instead.

Once the .dll is declared In LoadRunner script you can directly use this function:

lr_load_dll("mydll.dll")

Then you can call the functions in the .dll directly:
date = GetSysDate(char1, char2)

char1 and char2 and the names of variables

Note: Within a header file you can also define other user defined functions to be called within the script. This process is followed in most of the situations as working with DLL is costlier for simple functions which can be created within a header file.

Different Ways To Do Correlation

Different Ways To Do Correlation:

1. Generation Log

One of the common options in loadrunner is generation log. You will take the left and right boundary and search in the generation log and use CTRL+F and find the request name and place the web_reg_save_param before that request.

2. Replay Log

Sometime you do not find correlation value in generation log than the alternative way is go to run time settings and click on Log->Extended Log-> "Data Returned by Server" option and replay the script. Once you replay the script you will useCTRL+F and find the left and right boundaries. Sometimes replay log may fail or it will take a long time if you select “data returned by server” as it is printing all the response to the replay log then the alternate method to use is  lr_set_debug_message. 

3. Redirection

If you are not able to find the value in generation log and replay log then there might be 301 or 302 redirection.  Find out the pages that have 301 or 302 redirection. Once you find the pages that have 301 redirection go to that page manually in your browser, try to find the left and right boundary values by using view source (Left Click on the page -> "View Page Source" in chrome and "View Source" in internet explorer).

4. Text Flags:

Sometime you find the value, but the left and right boundaries will by changing dynamically then the alternate option is using text flags SaveLen and SaveOffset.

5. Automatic Correlation (Design Studio):


One of the best method that has from loadrunner 11.5 and loadrunner 12 is updated automatic correlation called design studio. It has improved a lot from this version. You can do the scripting at a faster pace by using this option.

Once you record the application go to Design-> Design Studio. The Design Studio will highlight the different values that need to be done correlation. Based on our requirement, we will select the value click on correlate value. We can also add it as “Add as Rule”. It will be easy if we are reusing the correlation in other scripts.

Note: Make sure you select the following option:

Go to Recording Options ->Correlation->Configuration-API and select web_reg_save_param_ex.  You can also use web_reg_save_param_regexp as well. I prefer using web_reg_save_param_ex.

Wednesday, 26 March 2014

What is 90 percentile?

What is 90 percentile?

90 percentile is average of 90% of the response times, here arrange the 100 response times from good to bad then eliminate the worst 10% of the response times. Then calculate the average for 90% of the response times.

Example: The response times for an application for 10 users is
2,4,3,8,9,16,6,8,3,10 then arrange them from Good to bad 

2,3,3,4,6,8,8,9,10,16 

Then take the average for 90% of the response times 2,3,3,4,6,8,8,9,10 (eliminate the 16) is 5.88.
Overall (100%) response time is 10.94 

Why 90 percentile required:-
End users need to satisfy with the application response time / speed. Then users should increase other wise users won't use that application. For satisfaction calculation purpose Performance testers uses the 90 percentile. Means 90% of the users satisfying with that response time, remaining 10% users not satisfying with that response times.

What is concurrent users and simultaneous users ?

What is concurrent users and simultaneous users ?

For example,  bank application has below transactions     
                      1. Login                          
                      2. Account summary                      
 ---------------------------Transfer money Action ---------                          
                      3. Click Transfer funds                         
                      4. Select "Beneficiary"                          
                       5. Enter "Amount"                          
                       6. Transfer                           
                       7. Enter "User id" and  Password and click "Confirm"--------------------------------------Transfer Money Action end--------                           
                         8.Log out

So we have 8 transaction for this application and we have one Action (Transfer Money is one action but in that action you can have 5 transaction).

Concurrency : Performing same activity at a time by all users.Mean 100 users are login into the application at a time. But simultaneous users are login into the application one by one. Concurrency has various levels

           1.Transaction concurrency          
           2.Business Process Concurrency           
           3.Application Concurrency 

Transaction concurrency :

We need to test the application with 100 concurrent users, Means "All users(100 users) should perform the same transaction (login or   Account summary .... or  Logout) at a time" this is called transaction level concurrency.

Business Process Concurrency:

We need to test the application with 100 concurrent users for Transfer money Business action, means  "All users(100 users) should perform the same Transfer money action (here may be 30 users are clicking "transfer funds, 20 users are on selecting "Beneficiary", 20 users are in enter "Amount" page,10 users are in "Transfer" page  and 20 users are Enter "User id" and  Password and click "Confirm" ). 
Overall 100 users should be in transfer money action.

Application Concurrency :

All 100 users should perform different transaction or same transaction but at any time 100 user should be accessing the application.

Simultaneous users:  All 100 users are login into the application one by one.

Web_find and web_image_check function example and Usage

Web_find and Web_Image_check function are used to find the specified text in the response of the HTML page. This function is only support in HTTP/HTML protocol based script. You should need to make sure that do the following changes in the run time settings before you use these two functions.

Go to Vuser -> Run-time Settings
Go to internet Protocol -> Preferences
Select the “Enable Image and Text Check” check box.
Web_find and web_image_check  will throw an error if the text or image does not found in the response.
For example if you want to set error when some text found. Then use the following example.

Example:
web_reg_find("Text=404", "Fail=Found", LAST);

If you do not want to throw an error regardless of the condition then use web_reg_save_param function with "Notfound=warning" option.

Example:

web_reg_save_param("NameCheck", "LB=Hi", "RB=Welcome to Loadrunner","Notfound=warning", LAST);

Web_find and web_image_check do not give the number of occurrences of the text/image. To find this we can use web_reg_find function. In web_reg_find we have “Save Count” option with this we can find out the totoal number of occurrences of text/image. web_find and web_image_check is only for  HTTP/HTML scripts. web_reg_find can be used with both  HTTP/HTML and URL based scripts.

Example:

web_reg_find("Text=loadrunner", "SaveCount=loadrunner_count", LAST);