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).
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}"));
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 );
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);
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);