Incorporate JavaScipt into a LoadRunner Web script

Incorporate JavaScipt into a LoadRunner Web script

Either use custom C coding or the JavaScript template solution

There are two ways to resolve this:

1. Add custom C code for the logic implemented by the JavaScript.


2. Use the JavaScript solution. This solution is build into LoadRunner 7.x and above. Please refer to the following for steps to incorporate JavaScript.

  1. Record your script in VuGen using the Web (HTTP/HTML) protocol.
  2. Go to File -> New and select "JScript template protocol."
  3. Copy and paste the code from step 1 into the Action section of the JScript template.
    • You need to change all the web_url function calls to web.url.
    • The function calls here take only two arguments; you need to delete all the subsequent arguments.


Change from Change To
"Name=username", "Value=userid", ENDITEM,
"Name=password", "Value=pwd", ENDITEM,
"Name=remember", "Value=<OFF>", ENDITEM,
"Name=x", "Value=0", ENDITEM,
"Name=y", "Value=0", ENDITEM,
new Array("Method=POST",
new Array(new String("Name=username"), new String("value=userid"),
new String("Name=password"), new String("value=pwd"),
new String("Name=remember"), new String("value="),
new String("Name=x"), new String("value=0"),
new String("Name=y"), new String("Value=0") ));
  • Go to the section called global.js and uncomment the statement var web = new ActiveXObject("LoadRunner.WebApi") to enable Web API replay. Copy and paste your JavaScript to the bottom of this section.
  • Make sure that you reference the JavaScript by calling the function in the Action section.


  1. Hello Abdul,
    I wonder, is it possible to script (in either c or java/javascript) inside a vuser recorded script to controll/manipulate elements, clicking radio-buttons and so forth on a web app/page using Ajax and being under test?

    Problem is that when running a vuser script against a web app implemented using Ajax I need to manipulate page elements in order to get the script running further (using http-protocol) and because http-protocol is focused on recording http-traffic as in web requests and responses the manipulation/client side behavior is not captured during recording.

    Best Regards Magnus

  2. Your blog the best. Few times I found here answers for my questions which I can’t find anywhere else. Thanks a lot.
    P.S. Sorry for my bad english.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s