Monday, September 30, 2013

Run JavaScript from Vugen - web_js_run

web_js_run runs the specified JavaScript from LoadRunner Vugen. Consult the function reference for more details. This is supported from LoadRunner 11.5 onward.

I will be providing a working example below.


Action()
{
web_js_run(
"Code=getQuotes(LR.getParam('symbol'));",
"ResultParam=param",
SOURCES,
"File=XMLHTTPRequest_sync_sample.js"ENDITEM,
LAST);

return 0;
}


Create the below XMLHTTPRequest_sync_sample.js under Extra Files

var req2;
function getQuotes(mySymbol)
{
var myURL=
'http://download.finance.yahoo.com/d/quotes.csv?s=' + mySymbol + '&f=nsl1op';
req2 = false;
// branch for native XMLHttpRequest object
try {
req2 = new XMLHttpRequest();
catch(e) {
req2 = false;
}
if(req2) {
req2.open("GET", myURL, false);
req2.send("");
}
return req2.responseText;
}

Some data you can use for symbol parameter :

symbol
FLWS
FCTY
FCCY
SRCE
FUBC
VNET
JOBS
EGHT
AVHI
SHLM
AAON
ASTM
ABAX
ABMD
AXAS
ACTG
ACHC
ACAD
ACST
AXDX

Sample output.log from the execution:

Starting iteration 1.
Notify: max connections per server : 2
Starting action Action.
Action.c(3): web_js_run started   [MsgId: MMSG-26355]
Action.c(3): Started Sync download of URL="http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op"   [MsgId: MMSG-26000]
Action.c(3): t=1588ms: Connecting [0] to host xx.xx.xxx.xx:80   [MsgId: MMSG-26000]
Action.c(3): t=1614ms: Connected socket [0] from yy.yyy.yy.yy:33504 to xx.xx.xxx.xx:80 in 25 ms   [MsgId: MMSG-26000]
Action.c(3): t=1614ms: 249-byte request headers for "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op" (RelFrameId=1, Internal ID=1)
Action.c(3):     GET /d/quotes.csv?s=FELE&f=nsl1op HTTP/1.1\r\n
Action.c(3):     User-Agent: Mozilla/5.0 (compatible; MSIE ; Windows; Trident/4.0)\r\n
Action.c(3):     Accept-Encoding: gzip, deflate\r\n
Action.c(3):     Accept-Language: en-US,en;q=0.5\r\n
Action.c(3):     Accept: */*\r\n
Action.c(3):     Connection: Keep-Alive\r\n
Action.c(3):     Host: download.finance.yahoo.com\r\n
Action.c(3):     \r\n
Action.c(3): t=1646ms: 538-byte response headers for "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op" (RelFrameId=1, Internal ID=1)
Action.c(3):     HTTP/1.1 200 OK\r\n
Action.c(3):     Date: Mon, 30 Sep 2013 23:16:06 GMT\r\n
Action.c(3):     Set-Cookie: B=3vbfeq994k1hm&b=3&s=cf; expires=Thu, 01-Oct-2015 23:16:06 GMT; path=/; domai
Action.c(3):     n=.yahoo.com\r\n
Action.c(3):     P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PS
Action.c(3):     D IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV IN
Action.c(3):     T DEM CNT STA POL HEA PRE LOC GOV"\r\n
Action.c(3):     Cache-Control: private, no-cache, no-store\r\n
Action.c(3):     Expires: -1\r\n
Action.c(3):     Pragma: no-cache\r\n
Action.c(3):     Connection: close\r\n
Action.c(3):     Transfer-Encoding: chunked\r\n
Action.c(3):     Content-Type: application/octet-stream\r\n
Action.c(3):     \r\n
Action.c(3): t=1660ms: 9-byte chunked response overhead for "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op" (RelFrameId=1, Internal ID=1)
Action.c(3):     000002e\r\n
Action.c(3): t=1660ms: 7-byte chunked response overhead for "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op" (RelFrameId=1, Internal ID=1)
Action.c(3):     \r\n
Action.c(3):     0\r\n
Action.c(3):     \r\n
Action.c(3): t=1668ms: 46-byte chunked response body for "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op" (RelFrameId=1, Internal ID=1)
Action.c(3):     "Franklin Electric","FELE",39.40,38.47,38.91\r\n
Action.c(3): t=1669ms: Closing connection [0] to server download.finance.yahoo.com - server indicated that the connection should be closed   [MsgId: MMSG-26000]
Action.c(3): t=1670ms: Closed connection [0] to download.finance.yahoo.com:80 after completing 1 request   [MsgId: MMSG-26000]
Action.c(3): t=1670ms: Request done "http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op"   [MsgId: MMSG-26000]
Action.c(3): Ended synchronous download of URL="http://download.finance.yahoo.com/d/quotes.csv?s=FELE&f=nsl1op"   [MsgId: MMSG-26000]
Action.c(3): Synchronous download ended/terminated with any other pending request(s). Synchronous downloads count=0   [MsgId: MMSG-26000]
Action.c(3): Notify: Saving Parameter "param = \"Franklin Electric\",\"FELE\",39.40,38.47,38.91\r\n".
Action.c(3): web_js_run was successful, 46 body bytes, 538 header bytes, 16 chunking overhead bytes   [MsgId: MMSG-26385]
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.





No comments: