In this post I will explain how to capture a value from server response and save to a text file using vugen.
How to capture and save to text file using loadrunner:
First I have recorded the script using bing.com and then i searched for IBM. We will get 10 results. I have captured all the 10 values and saved to a file.
Here is the code for that.
long fp;---Here I have declared fp to store the buffer that captured.
int i;
char *SearchValue;
char ch[1000];
web_url("www.bing.com",
"URL=http://www.bing.com/",
"Resource=0",
"RecContentType=text/html", ----------
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
web_reg_save_param_ex(
"ParamName=c_search",
"LB/IC=< h2 >=\"",
"RB/IC=\"",
"Ordinal=all",
SEARCH_FILTERS,
"Scope=body",
LAST);
web_url("search",
"URL=http://www.bing.com/search?q=ibm&qs=n&form=QBLH&filt=all&pq=ibm&sc=8-3&sp=-1&sk=&cvid=7edfd3e3530644d79148f56dfad4aa0a",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.bing.com/",
"Snapshot=t7.inf",
"Mode=HTML",
EXTRARES,
LAST);
fp=fopen("Loadrunnerz.txt","w");
for(i=1;i<=lr_paramarr_len("c_search");i++)
{
SearchValue = lr_paramarr_idx("c_search", i);
fputs(SearchValue,fp);
fputs("\n",fp);
}
int i;
char *SearchValue;
char ch[1000];
web_url("www.bing.com",
"URL=http://www.bing.com/",
"Resource=0",
"RecContentType=text/html", ----------
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
web_reg_save_param_ex(
"ParamName=c_search",
"LB/IC=< h2 >=\"",
"RB/IC=\"",
"Ordinal=all",
SEARCH_FILTERS,
"Scope=body",
LAST);
web_url("search",
"URL=http://www.bing.com/search?q=ibm&qs=n&form=QBLH&filt=all&pq=ibm&sc=8-3&sp=-1&sk=&cvid=7edfd3e3530644d79148f56dfad4aa0a",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.bing.com/",
"Snapshot=t7.inf",
"Mode=HTML",
EXTRARES,
LAST);
fp=fopen("Loadrunnerz.txt","w");
for(i=1;i<=lr_paramarr_len("c_search");i++)
{
SearchValue = lr_paramarr_idx("c_search", i);
fputs(SearchValue,fp);
fputs("\n",fp);
}
fclose(fp);
Hope, most of the code is self explanatory. If you have any doubts feel free to leave a comment.
i am very new to performance testing..can u please explain each and every line of the above written code.thanks
ReplyDeleteHi,
DeleteI suggest you to learn c language and loadrunner and web functions which will help you a lot in understanding the code.
hi sam thanks for your suggestion.yes i do know some basics of c but as you are asking me to learn web functions can i know where can we find these functions as an api so that i can go through.
DeleteDownload and Install the loadrunner http://loadrunnerz.blogspot.com/2013/11/how-to-download-and-install-hp_16.html
Deleteand in the help section you will find all the function reference.
go through following functions
Loadrunner Functions - which will start with lr_ - http://loadrunnerz.blogspot.com/2013/07/lr-functions-in-loadrunner-with-examples_9058.html
Web Functions - which will start with web_ -http://loadrunnerz.blogspot.com/2013/07/web-functions-in-loadrunner_1404.html
Thanks a lot sam.now i am going through.
DeleteYou are welcome
DeleteJust what I needed Sam, thank you!
ReplyDeleteYou are welcome..:)
DeleteHi Sam,
ReplyDeleteThanks a lot, this helped. I have an additional question on this: how do you combine the iterations results in a file? For ex: I am trying to run two users (i.e. two iterations in VuGen) but I can only see last user's correlated values. How do we not overwrite values in a file? I want to have both users' data in a file if I run 2 iterations.
Thank you.
Your comment on line:
ReplyDeletelong fp;---Here I have declared fp to store the buffer that captured.
fp is not for storing the buffer that captured. It is declared as a file pointer, which is used to "walk" the file.
Thank you for your correction
DeleteWhy was the below declaration done ?
ReplyDeletechar ch[1000];
Why was the below declaration done?
ReplyDeletechar ch[1000]; ??