Table of contents for Code Snippets(HP LoadRunner)
- Code Snippets(HP LoadRunner): Randomly Selecting an Array of Values and Using That Value As A Parameter by Howard Clark
- Code Snippets(HP LoadRunner): Decrypting Passwords and Using those Values in a web_submit statement by Howard Clark
- Code Snippet(HP LoadRunner) : FILE I/O and creating dummy XMLs
This is a code dump of a XML file generator I threw together to create multiple child nodes under what was essentially a header in the XML file, along with generating multiple files iteratively. The actual number of iterations was controlled by the number of iterations specified in the run-time settings, the number of child nodes to create is a parameter. I’ll only include a slice of code in this post, the entire file should be available for download with the post. This was done to support a custom web services testing effort involving electronic medical record(EMR) transfers.Create Sync Data File
Create_Test_File(char *header_filename, char *output_filename, int merge_count, int max_merge_count)
{
int count, output,patient_record_length,result_record_length,tail_record_length;
int result_lines,num_of_result_lines;
int total = 0;
char buffer[20000];
char * buffer_manual;
long h_file_stream;
long o_file_stream;
num_of_result_lines = atoi(lr_eval_string(“{Max_Num_Result_Lines}”));
//char * filename = “c:\\readme.txt”;
// Open the file with read access
/*if (merge_count == max_merge_count) {
if ((h_file_stream = fopen(header_filename, “rb”)) == NULL) {
lr_error_message (“Cannot open %s”, header_filename);
return -1;
}
// Read until end of file
while (!feof(h_file_stream)) {
// Read 1000 bytes while maintaining a running count
count = fread(buffer, sizeof(char), sizeof(buffer), h_file_stream);
lr_output_message (“%3d read”, count);
// Check for file I/O errors
if (ferror(h_file_stream)) {
lr_output_message (“Error reading file %s”, header_filename);
break;
}
total += count; // Add up actual bytes read
}
// Display final total
lr_output_message (“Total number of bytes read = %d”, total );*/
if ((o_file_stream = fopen(output_filename, “ab”)) == NULL) {
lr_error_message (“Cannot open %s”, output_filename);
return -1;
}
//Write Patient Header
/*output = fwrite(buffer, sizeof(char), total, o_file_stream);
//fwrite(&sd, sizeof(struct student_data), 1, file);
total = 0;
if (output > 0) {
lr_output_message (“Successfully wrote a header of size %d bytes”, output);
}*/
//buffer_manual = lr_eval_string(“\n\r
lr_advance_param(“Root0_Part1”);
buffer_manual = lr_eval_string(“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
//”\n\r
//”\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
//”\n\r
//”\n\r
//”\n\r
“\n\r
“\n\r
“\n\r
// Close the file stream
/*if (fclose(h_file_stream))
{
lr_error_message (“Error closing file %s”, header_filename);
}*/
//} //terminate loop for header and result qualifier info
//Write CDF Patient Data
patient_record_length = strlen(buffer_manual);
output = fwrite(buffer_manual, sizeof(char), patient_record_length, o_file_stream);
//fwrite(&sd, sizeof(struct student_data), 1, file);
total += output; // Add up actual bytes wrote
if (output > 0) {
lr_output_message (“Successfully wrote a patient record of size %d bytes”, total);
}
total = 0;
for (result_lines = num_of_result_lines; result_lines >= 0; result_lines–)
{
lr_advance_param(“Root2_Part1”);
lr_advance_param(“Root2_Part2”);
buffer_manual = lr_eval_string(“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
“\n\r
//Write Results
result_record_length = strlen(buffer_manual);
output = fwrite(buffer_manual, sizeof(char), result_record_length, o_file_stream);
//fwrite(&sd, sizeof(struct student_data), 1, file);
total += output; // Add up actual bytes wrote
if (output > 0) {
lr_output_message (“Successfully wrote a result record of size %d bytes”, total);
}
total = 0;
lr_output_message (“Successfully wrote a result record number %d “, result_lines);
}
buffer_manual = lr_eval_string(“\n\r”
“\n\r“);
//Close Results Node
result_record_length = strlen(buffer_manual);
output = fwrite(buffer_manual, sizeof(char), result_record_length, o_file_stream);
//fwrite(&sd, sizeof(struct student_data), 1, file);
total += output; // Add up actual bytes wrote
if (output > 0) {
lr_output_message (“Successfully closed a result record of size %d bytes”, total);
}
total = 0;
// Close the file stream
if (merge_count == 0) {
buffer_manual = lr_eval_string(“\n\r”
“\n\r”
“\n\r”);
tail_record_length = strlen(buffer_manual);
output = fwrite(buffer_manual, sizeof(char), tail_record_length, o_file_stream);
lr_output_message (“Successfully closed a result file”);
}
if (fclose(o_file_stream)) {
lr_error_message (“Error closing file %s”, output_filename);
}
return 0;
}
Vishwanath // Jun 16, 2014 at 10:02 am
i want to replace a particular string in a file.
My file content is of 4 line like below
john
deer
marry
california
i want to replace california with like// or $$ or 666 usign C in load runner
Lyman Aliff // Jul 16, 2019 at 8:45 am
Hurrah! In the end I got a weblog from where I be capable of in fact get useful information concerning my study and knowledge.|
Cythia Rocchio // Jul 16, 2019 at 9:39 pm
Have you ever considered creating an ebook or guest authoring on other websites? I have a blog centered on the same ideas you discuss and would love to have you share some stories/information. I know my visitors would enjoy your work. If you’re even remotely interested, feel free to shoot me an email.|
Emmy Chavez // Jul 20, 2019 at 12:46 pm
I go to see each day a few websites and information sites to read content, except this web site gives quality based posts.|
Myung Benshoof // Jul 26, 2019 at 10:08 am
Very good information. Lucky me I recently found your blog by chance (stumbleupon). I’ve saved as a favorite for later!|
Rodolfo Sorn // Jul 27, 2019 at 9:24 pm
Hi there to every one, the contents present at this website are actually remarkable for people knowledge, well, keep up the good work fellows.|
Stephan Groen // Jul 28, 2019 at 11:51 am
Hi there, I found your web site by the use of Google whilst searching for a related subject, your site came up, it seems to be good. I’ve bookmarked it in my google bookmarks.