Use LoadRunner to download the file and save it to your local device.

Source: Internet
Author: User
Some people often ask on the forum how to make LoadRunner download files and save them locally.

At first glance, this problem should not be a problem: LoadRunner records the interaction between the client (browser) and the server, and naturally records the action of the downloaded file and receives all the content of the downloaded file, however, if you use LoadRunner to try such a job, you will find that there are no statements related to the downloaded file in the script recorded by LoadRunner.

In fact, there is no way or action in the HTTP protocol to identify the action of "downloading files". For the HTTP protocol, download files or request pages, it is just a get method. As for the dialog box that prompts us to give a user name when we download the file, the client determines that we are requesting a file and processing it by itself.

So, how can we let LoadRunner complete this job?

Through the above analysis, we already know the following facts:

1. file requests are requested through the get method;

2. LoadRunner has recorded the file request sent by the client and can receive the file content;

Therefore, we can obtain the file content from the response of the LoadRunner's request through the association method, and then generate the file through the file operation method of LoadRunner.

From the recording log recorded by LoadRunner, we can see the specific request and request response information:

From this we can see that we only need to associate the following statements to obtain the file content.

Web_url ( " Viewfile. asp " ,
" Url = http://www.testage.net/bbs/viewFile.asp? Boardid = 25 & id = 217 " ,
" Resource = 0 " ,
" Reccontenttype = text/html " ,
" Referer = http://www.testage.net/bbs/dispbbs.asp? Boardid = 25 & id = 5187 & page = 1 " ,
" Snapshot = t16.inf " ,
" Mode = html " ,
Extrares,
" Url = viewfile. asp? Boardid = 25 & id = 217 " , " Referer = http://www.testage.net/bbs/dispbbs.asp? Boardid = 25 & id = 5187 & page = 1 " , Enditem,
Last );

After obtaining the file content, you can use LoadRunner's fopen, fwrite, and fclose functions to save this part of content to the local file.

// Get the file length in the response
FLEN = Web_get_int_property (http_info_download_size );

If (FLEN >   0 )
{
// Open a file in write mode
If (Filedes = Fopen ( " C: \ test.rar " , " WB " )) = Null)
{
Lr_output_message ( " Open File failed! " );
Return   - 1 ;
}
// Write File Content
Fwrite (lr_eval_string ( " {Fcontent} " ), FLEN, 1 , Filedes );
// Close file
Fclose (filedes );
}

Click to download the complete script file.

Note: When using this script file, modify the values of the username and passwd parameters.

Of course, this script simply implements the file download and save local functions. If we want to use different names for each download and save to a local file, or you want to dynamically generate a suffix based on the actual file suffix, you need additional work. Readers can think about how to implement it on their own. Pai_^

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.