Coding date and time parameters in Loadrunner

Applications often require you to provide date and time in the requests. Here I will show how this can be easily achieved in Loadrunner for basic and multi timezone site with code samples.

First the basics: If you would like to get access to the current date, the easiest way is to create a new parameter with Date/Time type. To do that:

  1. Open the Parameter List dialog (hotkey: Ctrl+L),
  2. Click New, and give a name to your new parameter
  3. Set the Parameter type to “Date/Time”.
  4. 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, here you can select when the value of the date/time parameter is updated (each occurrence, each iteration, or only once).
Parameter List dialog in Loadrunner VuGen. Select Date/Time type.

This approach is powerful 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. e.g. A multinational site, serving UK and US where the date formats are different

It is possible to define multiple rogaine vs propecia 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 Loadrunner 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 programatically 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 code snippet 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);  

2 thoughts on “Coding date and time parameters in Loadrunner

  1. Hi Richard Pal,

    in my application i want to caputure a date by using web_reg_save_param and i want to increase the caputured date by one day, that date is changing each and every time so i cant go for date and time parameteriation.

    could please help me to do.

Leave a Reply

Your email address will not be published. Required fields are marked *