Sunday, November 3, 2013

The art of reusing the code snippets in loadrunner


Problem:
While working in Loadrunner, you may across the situation where some codes/functions are repeated in most of the scripts. In that case, you can create one function and reuse the function in all the scripts. It would help you to reduce your effort in terms of scripting and time. 

Solution:

This can be achieved by creating the header file. Now we will see how to create the header file and reuse the code in loadrunner.

Steps:
1. Open the notepad and write the below function.

#ifndef _MYCODES_H_
#define _MYCODES_H_

int multiplyNumbers(int arg1, int arg2, int arg3)
{
     return arg1 * arg2 * arg3;
}
#endif

PS: This is an example function to calculate the multiplication of three numbers.

2. Save this file as "MyCodes.h" in the following path
<Loadrunner Installation Directory>\include


Now you created a header file. You can use this header file in script by calling #include "MyCodes.h" as preprocessing directory in Global.h

How to call the function in loadrunner script

1. Include the header file in Global.h


2. Call the function available in header file in action


Hope this might help for you to reuse your codes and reduce the effort in time and cost.

1 comment:

  1. Hello,

    is it possible for Vugen scripts like login, logout and SQL queries? if possible, what about parameters, correlation of scripts, is it still works same way?

    ReplyDelete

Linux Series - SED Utility/Package - 4. Deleting Lines

Let’s explore sed’s explicit delete command, which you specify by using the option 'd'. Again, we are using the sample file named &#...