Sunday, May 27, 2012

Date Randomization in LoadRunner

One of the common requirements that a performance tester may experience is randomizing the date.

For example in a online booking of train ticket or air tickets, we may want to book a ticket for a post date which can be any where between tomorrow or 60 days from today. Usually if it is a date is constant, that can be parameterized in LoadRunner. If thats not a fixed date and needs to be randomized, the below code will be helpful.

rand() is a C function that is used to generate a random number.
rand()%30 will give us a random number any where between 0 -29.

randNum = rand()%30 +1 //gives you a random number anywhere between 1 - 30

lr_save_datetime("%d/%m/%Y", DATE_NOW + ONE_DAY*randNum, "JrnyDate");

lr_save_datetime() is the loadrunner function to save a date of a specified format to a loadrunner variable.

In the above example, the date in the format of Date/Month/Year (25/05/2012) is saved to a LoadRunner parameter called "JrnyDate". DATE_NOW gives us the current date and ONE_DAY*randnum will give us a future random date.

Hope this information is helpful.

2 comments:

  1. The Information which you provided is very much useful for those who are learning Testing Tools.. Thank you for your valuable information on Testing Tools Online Training

    ReplyDelete