Sunday, January 26, 2014

File Operations In Loadrunner With Examples


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);
    }
fclose(fp);

Hope, most of the code is self explanatory. If you have any doubts feel free to leave a comment.



No comments:

Post a Comment