creating loadrunner functions
As we all know, creating functions has its benefits, and the rule of thumb is that if you’re going to use something more than once, its always better to create a function and call that function. Loadrunner is no different.
This post is quite a simple technique that is probably very well known in the community, so I’ll keep it short.
There are 2 ways to create a function.
The clunky way, is to write the function and place it in the vuser init, after the vuser init code:
vuser_init() { Login; go to search page; search_for 1; return 0; } //mishmashmoo's functions// //function : Buffer //Creates a 2mb buffer for html paramter buffer() { web_set_max_html_param_len("2097152"); web_reg_save_param("buffer","LB=","RB=","Search=Body",LAST); return 0; }
In the example, I have just created a function that creates a 2mb buffer for the web_reg_save_param function, and then I have created and saved the body of the page to the ‘buffer’ parameter.
It’s ok with 1 function but there is a good chance you’ll be creating more and after a while, your vuser init could get quite messy. If you’re working on more than 1 script you will start to have problems, copying the vuser init functions into every script is both annoying, and difficult to version.
The solution is to create a loadrunner functions file and add it to the loadrunner headers. This is easier than it sounds.
Simply take your functions from the vuser init and create loadrunner headers file. The format is filename.h
In loadrunner, there is an action named
#include "\\folderName\subFolder\filename.h"You must save, close, and then re-open the file. The headers only get read when the file is opened, so any changes to the globals.h file will require a shutdown of the script before they are executed.
Here is an example of one of my header files.

Invoking the function is simple, as you would in any other language.
//Invoking buffer// buffer(); //submit web data // web_submit_data("main.jsp", "Action=http://mishmashmoo.com", "Method=POST", "RecContentType=text/html", "Referer=http://mishmashmoo.com", "Snapshot=t40.inf", "Mode=HTML", ITEMDATA, "Name=s_state", "Value=blah", ENDITEM, "Name=s_activity", "Value=null", ENDITEM, "Name=s_params", LAST);
Enjoy!