Sunday, June 9, 2013

Generate unique file name with web_save_timestamp_param function in load runner

To get the unique file name in LoadRunner , first generate the unique file name using LoadRunner parameter by using web_save_timestamp_param() function.

web_save_timestamp_param() function saves the current timestamp to LoadRunner parameter. Timestamp is the number of milliseconds since midnight January 1st, 1970 (also known as Unix Epoch).

Code Snippet: 

  web_save_timestamp_param("TimeStamp"LAST);
  lr_output_message("Timestamp: %s"lr_eval_string("{TimeStamp}"));

The Output in replay log will be:








For generating the unique file names, we need to get unique ids per virtual users using the lr_whoamiLoadRunner() function. The function Returns information about the Vuser executing the script.The syntax will be
 
void lr_whoami ( int *vuser_id, char *sgroup, , int *scid );

vuser_id :A pointer to an output argument to store the Vuser ID number.
sgroup :A pointer to an output argument to store the name of the Vuser Group.
scid :A pointer to an output argument to store the Scenario or Session step ID number.

Final code will be:

char UniqueFile[256];
int  vuserid, scid;
char *groupid;
                    
   web_save_timestamp_param("TimeStamp"LAST);
   lr_output_message("Timestamp: %s"lr_eval_string("{TimeStamp}"));
  lr_whoami(&vuserid, &groupid, &scid); web_save_timestamp_param("TimeStamp"LAST); 
  printf(UniqueFile, "%s_%d_%d_%s",    lr_eval_string("{TimeStamp}"),vuserid,scid,groupid);
  lr_output_message("File name: %s", UniqueFile);

Output of 2 iterations:
 

So you may get a unique file name by adding the necessary file extension such as txt, pdf, etc. In the LoadRunner Controller, it will function for any quantity of concurrent virtual users.