Sei sulla pagina 1di 2

web_find: web_find will be processed after the response of the request comes.

So , this function will be there after the request in VuGen script. web_reg_find: web_reg_find will be processed before the request sent. And the c heck value will be checked in the response of the specific request. Thats the reason this function will be there before the request in VuGen script. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Date Randomization in LoadRunner One of the common requirements that a performance tester may experience is rando mizing the date. For example in a online booking of train ticket or air tickets, we may want to b ook 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 Lo adRunner. If thats not a fixed date and needs to be randomized, the below code w ill 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 form at 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.

lr_save_datetime Assigns the current date and time to a parameter. void lr_save_datetime (const char *format, int offset, const char *name); format The format of the retrieved data/time information. offset Offset from the current date and time, using the constants: DATE_NOW, TIM E_NOW, ONE_DAY, ONE_HOUR, ONE_MIN. For example, TIME_NOW + ONE_HOUR. name The name of the parameter to store the date/time information. The supported format codes can be found at: HP LoadRunner Online Function Referen ce > Utility Functions: C Language (LR) > Datetime Format Codes Eg: lr_save_datetime ("%B %d, %Y", DATE_NOW+ONE_DAY, "pDate2"); lr_output_message ("Tomorrow s Date is %s", lr_eval_string ("{pDate2}"));

Generating a Random Number in load runner between a specified range There are situations when you need to generate numbers between specific range ex ample for phone number it should be of 10 digits .

Action() { //srand is called before rand int Diff=0; int Rand_number; int phoneNumber =0; char temp[20]; lr_save_string("1111111111","Numbera"); lr_save_string("9999999999","Numberb"); srand(time(NULL)); Diff = atoi(lr_eval_string("{Numberb}")) - atoi(lr_eval_string("{Numbera}")); Rand_number = rand() % Diff; phoneNumber=Rand_number + atoi(lr_eval_string("{Numbera}")); itoa(phoneNumber,temp,10); lr_save_string(temp,"PhoneNumber"); lr_output_message("Value = %s" , lr_eval_string("{PhoneNumber}")); return 0; } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Potrebbero piacerti anche