Saturday, March 5, 2022

Read or Write a Notepad with load runner or Read Write text file in load runner Vugen

If we want to alter a text file(.txt) with loadrunner or we may need to read or write the notepad,we can simply use load runner inbuild functionalities.Here is the example.

Script code:

 char * filename =”C:\\easytech\\loadrunner\\testfile.txt”; 
// {Use // quote instead of single (/) for defining path.}
long file;
char names[100];

Vugen Action:
Action()
{
fopen(filename, “r”);
if ((file = fopen(filename, “r”)) == NULL) {
lr_error_message (“Loadrunner cannot open the %s”, file);
return -1; }

while (!feof(file))
{
fgets(names, 200, file);  // here 200 decide the length of the contents in a line. So, if you have longer piece to read, you'll need to lengthen it.

if (!feof(file)) //if not at the end of file print names
{
lr_output_message(“%s”,lr_eval_string(names));
}
}
fclose(file);
return 0;

Hope this helps,Comment if you are facing any issues.