Using a header file
You can define the functions or variables in a header file so that you can share the information among different scripts. After you have created the header file, you need to use the #include directive in a LoadRunner script to refer to it via either of the following ways:
The following solution assumes the name of your header file is my_header_file.h.
1. If the header file is not in the script or the <LoadRunner>\include directory, you will have to specify the full path to it in the script:
#include “c:\\Application_A\\additional_include_files\\ my_header_file.h ”
You need include two two backslashes (\\). Make sure that the header exists on the remote LoadGenerator machine at the same location when running the test from Controller
2. If the header file is in the script folder, you need to add the following to the beginning of the script:
From the script directory open .usr file with a notepad.
Then, add the file under the [ExtraFiles] section of the script’s .usr file and save it.Example:
This will show the header file listed in the Controller as the file to transfer to remote LoadGenerator. Right-click on the script and select Details -> More -> Files in the Controller Design view. If you still do not see the file, click on “Add” to add the header file.
3. If the header file is in the <LoadRunner>\include directory, you need to add the following to the beginning of the script:
Make sure that you copy it to the remote machine during the load test.
4. As you can see, LoadRunner only scans through the script or <LoadRunner>\include for header files by default. It will ignore the $INCLUDE environment variable as well. If you would like LoadRunner to scan a different directory, such as C:\Application_A\additional_include_files, you can do the following:
It is recommended that you back up your files before you modify them.
- Create a file with the following line: -I<path to your additional include directory>
1. Create file called include in C:\temp.
2. Add the following line to the file:
- Add the following to the Vuser command line (could be through the MDRV.dat file): -compile_flags <Full path to the file saved in step #1>
1. Open <LoadRunner>\dat\MDRV.dat.
2. Edit the [lrun_api] section, adding the line:
- In the script, include the header file.Example:
#include ” my_header_file.h”
where my_header_file.h is in C:\Application_A\additional_include_files.
Note: If you want to run the script on a remote LoadGenerator, you need to make sure that the header file exists on the remote LoadGenerator