Tuesday, 20 May 2014

Date and Time parameter in Loadrunner Vugen

Some applications need you to provide date and time in the requests.
After scripting completed,If you would like to get access to the current date, the easiest way is to create a new parameter with Date/Time type. for that select the date in script and right click on it "Replace with a parameter"  give a name to your new parameter set the parameter type to “Date/Time”. then Open the Parameter List dialog by pressing
Ctrl+L.
In the Date/Time format list you can choose your desired date format, or create a custom one.

Pay attention to the “Update value on” drop-down box,as shown in the below screen here you can select when the value of the date/time parameter is to update like
  •  Each Occurrence
  •  Each Iteration
  •  Only Once




Note: Use this with care because you have access not only to the current date or time, but you can also offset it with a defined date or time. This can also factor in working days.

If the Application Under Test uses different date or time formats then you will probably need a different approach.

example: A multinational site, serving UK and US where the date formats are different.

Condition: It is possible to define multiple variants of the parameter (e.g. one to match US date format and one other to match UK), or this can be done programmatically.

Here is an example of the Load runner code to deal with this type of problem:

void saveFutureDate(int daysInFuture, char *paramName) {
char *dateFormat;
char *locale = lr_eval_string("{p_locale}");
if (strcmp(locale, "UK")==0) {
dateFormat = "%d-%m-%Y";
} else if (strcmp(pos, "US")==0) {
dateFormat = "%m-%d-%y";
} else {
dateFormat = "%Y-%m-%d"; // a default date format...
}
lr_save_datetime(dateFormat, DATE_NOW + ONE_DAY * daysInFuture, paramName);
web_convert_param(paramName, "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);
}


This functions sets the desired Loadrunner parameter with a date in a specified day offset in the future.

The function considers two date format, a UK and a US specific one. The right format is decided according to the “p_locale” parameter. Specify this it in a Parameter list with an appropriate selection strategy – random or sequential, or simply set it programmatically with lr_save_string() before invoking this function.

As a bonus, the function also converts the parameter to URL-encoded, so you can simply apply it later in a web request.

Here is a snippet of code how to use it:

lr_save_string("US", "p_locale");
saveFutureDate( 10, "p_arrivalDate"); // arrival Date will be 10 days ahead from now

web_url("List Intineraries",
"URL=http://www.yourapplication.com/usa/listBookings.html?arrivalDate={p_arrivalDate}",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.yourapplication.com/usa/",
"Snapshot=t33.inf",
"Mode=HTML",
LAST);

No comments:

Post a Comment