Loadrunner |
We all would be familiar with C file operations in loadrunner, like to open a text file, do some operations on it and then close the file. Now lets see how to handle the below scenario in loadrunner.
Scenario: Open a text file, write some content to it and upload it into a web application. Please note that each text file should be unique.
So this scenario during load test can be explained as, each user should upload a unique text file during each iteration after writing some content on it.
This can be achieved in loadrunner using C file operations. We can declare the file path & name and using fopen function open the text file and do some operation, save it and using fclose function we can close the file.
Code will be like
char * filename ="C:\\Text Files\\Sample.txt";
long file;
fopen(filename, "r");
if ((file = fopen(filename, "r")) == NULL) {
lr_error_message ("Cannot open %s", file);
return -1;
}
fclose(file);
But in our case each text file should be unique. So we need to parameterize the file path & name in the below line, so each time the file operations will be done on a unique text file.
char * filename ="C:\\Text Files\\Sample.txt"; (parameterize the file path and name)
and the code will be like
char filename[500];
long file;
strcpy((char *)filename,lr_eval_string("{P_FileName}")); // P_FileName is a loadrunner file parameter
fopen(filename, "r");
if ((file = fopen(filename, "r")) == NULL) {
lr_error_message ("Cannot open %s", file);
return -1;
}
fclose(file);
- Now the loadrunner file parameter P_FileName will hold the file path & name C:\\Text Files\\Sample.txt.
- lr_eval_string will extract the value from the parameter P_FileName and copy it to the character pointer variable filename.
No comments:
Post a Comment