This
function helps in many situations like:
1.
During the
data validation, we need to check some system generated data for thousands of
user ids.
e.g. If we have a banking application and
we need to check balance amount in every user’s account numbers, it’s really
tedious task to check manually thousands of user ids.
For situation like this, we create a
script which captures amount for user and then we can write this Amount into
external file using this function.
2.
During the
load test we need to write confirmation number generated for each order which
we have placed for having a count of how many orders we have placed.
We
can easily fulfill these kinds of requirements using this function.
Follow easy 4 steps.
a.
Place the
given function code in globals.h
ExportToFile (const char *buf,int len,char
*filename)
{
//char *filename;
long
pFile_User;
pFile_User=fopen(filename,"a+");
if(pFile_User!=NULL)
{ fwrite(buf,len,1,pFile_User);
//fputs("hi to all1",pFile_User);
fputs("\r\n",pFile_User);
fclose(pFile_User);
}
}
b.
Define the
buffer variables as well file pointers for the required files in globals.h.
char *buff_Amount,*buff_ConfNum;
unsigned long len_Amount, len_ConfNum;
char *file_user = "c:\\Amount.txt";
char *file_passwd =
"c:\\Confirmation_Number.txt";
c.
Correlate
the Amount or the confirmation number in the script.
web_reg_save_param("Amount","LB/IC=Amount=\””,"RB/IC=</span>",Ord=1",“Search=body",
LAST);
web_reg_save_param("Conf_Num","LB/IC=Conf_Num=\””,"RB/IC=</span>",Ord=1",“Search=body",
LAST);
web_submit_form("banking.pl",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart_name", "Value=London", ENDITEM,
"Name=date", "Value=11/20/2003", ENDITEM,
"Name=office "Value=101", ENDITEM,
"Name=FA", "Value=060", ENDITEM,
"Name=ActHolder", "Value=Robert",
ENDITEM,
LAST );
d.
Write the
given code below after this request to write the data in external file.
lr_eval_string_ext("{Amount}",strlen("{Amount}"),&buff_user,&len_user,0,0,-1);
lr_eval_string_ext("{Conf_Num}",strlen("{Conf_Num}"),&buff_passwd,&len_passwd,0,0,-1);
ExportToFile(buff_Amount, len_Amount, file_Amount);
ExportToFile(buff_Conf_Num, len_Conf_Num,
file_Conf_Num);
No comments:
Post a Comment