Tag Archives: custom code

Custom Codes in Vugen using System Commands


Sometimes there might be a requirement to keep some files in the LG machine for temporary use. Have the file included in the script which needs to be copied to LG machine. Use the below mentioned commands to create a temporary folder inside c:\temp folder and copy the file from script folder to newly created folder in LG machine. Once the use of file is completed, use the last command to delete the newly created folder. Char command1[]=”mkdir \”c:\\temp\\\ext_jar”;

Char command2[]=”xcopy /Y filename.pdf \”c:\\temp\\\ext_jar\””;

Char command3[]=”RD /S /Q \”c:\\temp\\\ext_jar\””;

System(command1);

System(command2);

Lr_think_time(5);

System(command3);

Loadrunner Custom Code to select more check box values


Note: checkboxvalueRaw is the list of correlated values which is being listed in the check boxes. It has to be checked in random numberr and submitted.

int i, j;

char checkboxvalue_param[100],temp_param[60], temp1_param[60];

web_reg_save_param(“checkboxvalueRaw”,”LB=XXXXX”,”RB=YYYYY”,”ORD=ALL”,”Notfound=warning”,LAST);

i=1;

j=(rand()%(atoi(lr_eval_string(“{checkboxvalueRaw_count}”)))+1);

lr_output_message (“i is %d, j is %d”, i,j);

do

{        sprintf (checkboxvalueRaw_param, “{checkboxvalueRaw_%d}”, i);

lr_save_string(lr_eval_string(checkboxvalueRaw_param), “checkboxvalue_sel”);

strcpy(temp_param, temp1_param);

strcat(temp_param, lr_eval_string(“{checkboxvalue_sel}”));

if (i<j)

{

strcat(temp_param, “,”);

}

strcpy(temp1_param, temp_param);

i=i+1;

}

while (i==j);

lr_save_string(lr_eval_string(temp_param), “checkboxvalue_sel”);

Loadrunner code to write a string in a file


char newvalue[15]=”I Love India”;
char *newvalue11,*newvalue12;
long pfile;
char *filename = “C:\\Sample.txt”;
newvalue11 = lr_eval_string(“{pFirstName}”);
newvalue12 = lr_eval_string(“{pLastName}”);
pfile = fopen( filename,”a+” );
if(pfile == NULL)
{
printf( “Error in opening the filename – %s “,filename );
}
fputs(newvalue,pfile );
fputs(“,”,pfile );
fputs(newvalue11,pfile);
fputs(“,”,pfile );
fputs(newvalue12,pfile);
fputs(“\n”,pfile );
fclose( pfile );

Access mode – Description:
r – Open an existing file for reading only.
w – Open a file for writing only. If the file does not exist create a new one. If the file exists it will be overwritten.
a – Open a file for appending only. If the file does not exist create a new one. New data will be added to the end of the file.
r+ – Open an existing file for reading and writing
w+ – Open a new file for reading and writing
a+ – Open a file for reading and appending. If the file does not exist create a new one.