Monday, October 22, 2012

Loadrunner How to Read Parameters From Javascript

Sometimes it is necessary to read data from the contents of a javascript file rather than an html page.  The javascript may have certain variables created at compile time that it is useful to correlate.  Because the javascript file may show up as extra resources in an http call, the contents of the file are not visible to web_reg_save_param, etc.  However, by adding an additional call, the javascript can be read as follows:

  • Get the .js file with a web_url call
  • Set content type to "text/js"
  • Set resource=1

The following gives an example of the method described.

Script


Action()
{
    web_reg_save_param("jsText", 
"LB=", 
"RB=", 
LAST ); 

    web_url("Test-Read-JS-File", 
        "URL=https://test.server.com/scripts/test.js", 
        "Resource=1", 
        "RecContentType=text/js", 
        "Snapshot=t1.inf",
        LAST);

return 0;
}


Console Output


Starting action Action.
Action.c(4): Registering web_reg_save_param was successful   [MsgId: MMSG-26390]
Action.c(9): Notify: Saving Parameter "jsText = HTTP/1.1 200 OK\r\nAccept-Ranges: bytes\r\nCache-Control: max-age=2592000\r\nContent-Type: application/x-javascript; charset=utf-8\r\nDate: Mon, 22 Oct 2012 22:39:40 GMT\r\nExpires: Wed, 21 Nov 2012 22:39:40 GMT\r\nLast-Modified: Fri, 19 Oct 2012
...
Action.c(9): web_url("Test-Read-JS-File") was successful, 614175 body bytes, 321 header bytes   [MsgId: MMSG-26386]
Ending action Action.

1 comment:

  1. Hello,
    The Article on Loadrunner How to Read Parameters From Javascript, gives detailed information about it. Thanks for Sharing about Testing tools For More information check the detail on the LoadRunner Testing here Software Testing Company

    ReplyDelete