Calling JavaScript Function

62 views
Skip to first unread message

Desh

unread,
Feb 13, 2008, 6:43:22 AM2/13/08
to LoadRunner
Hello All,

I have recorded the script using C language. I need to corelate a
dynamic values(time in this case, new Date().getTime();). which is a
Javascript function.

It is some who possible to get the value of this function(new
Date().getTime()).

thanks
desh

kiran badi

unread,
Feb 13, 2008, 7:56:01 AM2/13/08
to LR-Loa...@googlegroups.com
weg reg save param function

Dmitry Motevich

unread,
Feb 13, 2008, 8:28:14 AM2/13/08
to LR-Loa...@googlegroups.com
If JavaScript is being executed on client's side, then web_reg_save_param function will not work.
web_reg_save_param will captures nothing, cause time is being calculated on client.

Desh, you have to emulate JavaScript in LoadRunner VuGen script.
If you use C language protocol, then you can use 'time' function.

This is an example I prepared:

-- example started --
#include <stdio.h>
#include <time.h>

int main ()
{
    time_t seconds;
    double millisecs;
   
    seconds = time (NULL);
    millisecs = seconds * 1000;

    printf ("%.0f milliseconds since January 1, 1970", millisecs);

    return 0;
}
-- example finished --

Result is:
1202909194000 milliseconds since January 1, 1970

Comments:
  1. Please, note that Date.getTime() is a prebuilt JavaSscript method that returns the time elapsed from January 1st, 1970 to the current Date instance, in milliseconds (!).
  2. time() C-function returns time from January 1st, 1970 in seconds (!).
    That's why I multiplied value, returned by time(), by 1000,
  3. You can use sprintf to save a value to a string.

Any questions/comments?
--
Dmitry Motevich,
http://motevich.blogspot.com

Desh

unread,
Feb 13, 2008, 8:00:04 AM2/13/08
to LoadRunner
with web_reg_save function I dont get the value of new
Date().getTime();).

It just return (new Date().getTime();).


On Feb 13, 5:56 pm, "kiran badi" <kmb...@gmail.com> wrote:
> weg reg save param function
>
> On 2/13/08, Desh <bharat.desh...@gmail.com> wrote:
>
>
>
>
>
> > Hello All,
>
> > I have recorded the script using C language. I need to corelate a
> > dynamic values(time in this case, new Date().getTime();). which is a
> > Javascript function.
>
> > It is some who possible to get the value of this function(new
> > Date().getTime()).
>
> > thanks
> > desh- Hide quoted text -
>
> - Show quoted text -

kiran badi

unread,
Feb 14, 2008, 6:03:11 AM2/14/08
to LR-Loa...@googlegroups.com
JS are always executed on the client side Dmitry,its client side just executes the JS and sends the parameter to the server, so it can be correlated with WRSP and in case you are talking about AJAX, then yes still it can be captured but without seeing i would not like to comment on the AJAX side.
Depending on the way its executed you need to decide, but most of the time, it will be a part of the query string embedded in the link and so you can capture it with WRSP.

 

Dmitry Motevich

unread,
Feb 14, 2008, 12:07:56 PM2/14/08
to LR-Loa...@googlegroups.com
Kiran,

It is *impossible* to use web_reg_save_param function to capture a value, generated by JavaScript on client's side.
I'll try to explain why it is...

Since JavaScript generates a value on client's side, the value is not coming from server!
Web_reg_save_param function registers a request to parse the next page, coming from server. Since server does not generate the value, web_reg_save_param function will NOT capture it.

So, what we can to do with JavaScript?
There are not many solutions:
  1. Emulate JavaScript in your LR script
    I sent this solution in my previous email
  2. Save JavaScript code into external js-file, execute it with system() function
    Do not forget to add printing of calculated value to console.
    As I remember, system() function allows to read the output of executed command.
  3. Use Web (Click & Script) or AJAX (Click & Script) protocols.
    These protocols execute JavaScript on client side. So, the values will be generated correctly.

kiran badi

unread,
Feb 14, 2008, 12:35:32 PM2/14/08
to LR-Loa...@googlegroups.com
i have used it quite successfully with concurrent groups.you just need to understand as how the value is passed to server either in form of query string or timestamp or something else.then you need to parse it with WRSP.
But it varies from application to application and sometimes you might also need to code it that is follow whatever you have said.Please bear in mind value generated on client side has to be passed to server either in form of cookies, header or body.
i would always prefer to stay away from other 2 protocols as they are in nascent stage.

 

Dmitry Motevich

unread,
Feb 16, 2008, 3:56:15 PM2/16/08
to LR-Loa...@googlegroups.com
Kiran,
I don't believe to my eyes:

> i have used it quite *successfully* with concurrent groups.
> you just need to understand as how *the value is passed to server*
> either in form of query string or timestamp or something else.
> *then you need to parse it with WRSP*.

I'm repeating - web_reg_save_param does NOT capture values, generated on client.
It captures data *from server only*.

To prove my words, I've copied citation from LoadRunner 9.0 HP Online Function Reference on web_reg_save_param:
-- citation started --
web_reg_save_param is a registration type function. It registers a request to find and save a text string *within the server response*.
-- citation finished --
Reply all
Reply to author
Forward
0 new messages