So, I’m working at a new client, back doing the Loadrunner thing. One of the nice things about that is I get to re-use and refine code I’ve written previously for other clients. This article is going to contain some of these code snippets that I’ve used time and time again.
I’ve re-visited this code recently and found that a) it wasn’t very good, and b) I can do it better now – presented below is the better version. There will be an update inviting formatting etc.
And there’s no guarantee this is perfect.
Output to Text file
int WriteToOutputFile(char * string)
{
char *filename = "c:\\myfilename.txt";
long file_streamer;
if ((file_streamer = fopen(filename, "a+")) == NULL)
//open file in append mode
{
lr_error_message ("Cannot open %s", filename);
return -1;
}
fprintf (file_streamer, "%s\n", string);
fclose(file_streamer);
return 0;
}
Called like this:
WriteToOutputFile(lr_eval_string("bban_count: {bbanNumber_count} blah {bbanNumber_count}"));
I just added the function beneath vuser_init rather than creating a header file. For multiple vusers, it’s a good idea to parameterise the filename as they can’t all share. I recommend a vuser identification parameter as thats built in.
Or Timestamps for uniqueness.I also have a dos script for joining them all back up again since I tend to use this function for creating custom audit logs to track test data states as it moves through a scenario / test cycle.