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.

OR

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.

Example:

Change from Change To
web_url("www.yahoo.com",
"URL=http://www.yahoo.com/",
"Resource=0",
"RecContentType=text/html",
"Snapshot=t1.inf",
LAST);
web.url("www.yahoo.com",
"URL=http://www.yahoo.com/");
web_submit_data("MI","Action=http://www.mi.com",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://www.mi.com/?cmd=login",
"Snapshot=t2.inf"
"Mode=HTML"
ITEMDATA,
"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,
LAST);
web.submit_data("MI","Action=http://www.mi.com",
new Array("Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=hhttp://www.mi.com/?cmd=login",
"Snapshot=t2.inf",
"Mode=HTML"),
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.
Advertisements

2 thoughts on “Incorporate JavaScipt into a LoadRunner Web script

  1. Magnus Jensen Fuglerud

    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

    Reply
  2. sergonas

    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.

    Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s