Thursday, May 17, 2018

Loadrunner scripting useful functions

1.How to capture entire response in loadrunner using web reg save param?
using web_reg_save_param("EntireResponse","LB=","RB=","Search=Body",LAST);

2.Creating Random numbers in loadrunner?
int randomValue=Rand() %(Max -Min +1))+Min;

3.How to process and fetch a value from JSON body?
If you need to process from a response body. First Capture EntireResponse
web_reg_save_param("EntireResponse","LB=","RB=","Search=Body",LAST);

Now we have inbuilt function that is
lr_eval_json("Buffer=EntireResponse","JsonObject=EntireResponseJsonObject",LAST);

Now we have a json Object now using this we can using JSON query to capture the required data.
lr_json_get_valuess("JsonObject=EntireResponseJsonObject","ValueParam=capturedValue","QueryString=$..ValueObjectName",LAST);

4.How to generate future date using the LR inbuilt function?
For creating Future date or past date we have an inbuilt LR function that is
1.For Present Date:
lr_save_datetime("{DateFomat",DATE_NOW,"{DateLRParam}");

Example:
lr_save_datetime("%m/%d/%Y",DATE_NOW,"PresentDate");

2.Future Date:
lr_save_datetime("{DateFomat",DATE_NOW+(ONE_DAY*{NoOfDays}),"{DateFutureLRParam}");

Example:
lr_save_datetime ("%Y/%m/%d", DATE_NOW+(ONE_DAY*3), "FutureDate");

3.Past Date:
lr_save_datetime("{DateFomat",DATE_NOW-(ONE_DAY*{NoOfDays}),"{DatePastLRParam}");

Example:
lr_save_datetime ("%Y/%m/%d", DATE_NOW-(ONE_DAY*3), "PastDate");