Parameterising Unix/Posix timestamps in VuGen
A common question from people creating web-based VuGen scripts is how to handle timestamp values that are sent as part of a name/value pair in an HTTP request.
If we look at the example GET request below, two values immediately stand out as needing to be correlated.
1 2 3 4 5 6 7 8 9 | web_url("www.example.com", "URL=http://www.example.com/view?jsessionid=dYyvCMH1cxEc&ts=1231715057375", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://www.example.com/", "Snapshot=t2.inf", "Mode=HTML", LAST); |
The jsessionid should be easy to correlate, but the ts value usually causes some confusion.
An experienced eye will notice that 1231715057375 looks like a timestamp in Unix Time, which is defined as the number of seconds since 00:00am on January 1, 1970. An even more experienced person will notice that the number is actually in milliseconds, rather than seconds, so it is probably being generated with the JavaScript getTime() method.
In this case, 1231715057 translates to Sun, 11 Jan 2009 23:04:17 UTC.
As this value is being generated on the client (i.e. the web browser), it will be impossible to correlate, because the actual value never appears in the HTML that is returned by the web server before the value is used in a request.
The solution is to create the timestamp value in your VuGen script at runtime, rather than trying to correlate the value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // Using standard C library functions to get timestamp in seconds. long t; time(&t); lr_save_int(t, "secondsTimeStamp"); lr_output_message("Seconds: %s", lr_eval_string("{secondsTimeStamp}")); /* Using a LoadRunner function to get timestamp in milliseconds. Function documentation: web_save_timestamp_param saves the current timestamp. In some applications, VuGen replaces all non-empty timestamps in the script with a parameter. To save the value of this parameter, VuGen automatically generates a call to web_save_timestamp_param. The value saved is the number of milliseconds since midnight January 1st, 1970. */ web_save_timestamp_param("msTimeStamp", LAST); lr_output_message("Milliseconds: %s", lr_eval_string("{msTimeStamp}")); |
As creating a timestamp value is so easy to do, there is no excuse for leaving hardcoded values in your VuGen script from your initial recording, even if the script seems to run without error.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
February 9th, 2009 at 2:24 pm
Interesting piece of trivia…
On Friday the 13th, 2009 at 11:31:30pm UTC UNIX time will reach 1,234,567,890.
…and just after 03:14:07 UTC on Tuesday, 19 January 2038, the 32-bit integer that stores the timestamp will roll over to -2147483648. This is known as the “Unix Millennium bug“.
June 5th, 2010 at 1:10 am
Hello,
I am facing a correlation problem. The problem is the dymanic value needed to correlation occurs at the first letters of the html returned by the server. The problem is that there is no LB because the HTML starts with the dymanic value. I tried to leave the LB blank but then the parameter is not capturing anything. Any ideas about this?
Regards,
Ray
August 6th, 2010 at 4:45 am
Good article Stuart! I found a EPOCH time conversion routine in ‘C’ which has proven successful many a times. But I will try this solution sometime too…
November 30th, 2010 at 11:30 am
Concise and exactly what I needed. Thanks