LoadRunner Download File script

Source: Internet
Author: User

LoadRunner download File script looking at Shi about pezybase TestReport, found that it is useful to JMeter (HTTP protocol) concurrent test download files, considering the later may need to be in the company pezybase concurrent download, the previous used LoadRunner download file script rerun and tidy up. first, the HTTP protocolLoadRunner using the HTTP protocol is unable to record to the download process, will only send a download request to the server, in fact, the server has returned the data to the client, but LoadRunner is not recorded to save the file to the local process, So it is necessary for us to manually save the content received locally. (The complete process of uploading files by HTTP protocol can be recorded directly, and has been used in UC). Note:The following are some of the LR functions used in the script below, as well as some basic C language file manipulation methods. In the script can also add some judgment to the success of the transaction and the file size is correct, such as the judgment; Web_reg_save_param: Associate function, put in front of the HTTP request, save the content returned by the request, Web_url:http request function, send the request to the specified URL , the download file is the direct download of the link to send the request; Web_get_int_property: Gets the length of the file returned by the downloading request; Web_set_max_html_param_len: Set WEB_SET_MAX_HTML_PARAM_ The maximum length of the parameter in the Len method is greater than the size required to download the file;
The Action () {int flen;//defines an integer variable to save the size of the file filecontent;//a file handle, that is, the contents of the file char filename[]= "";//Save file path and file name char * Strnumber;strnumber=lr_eval_string ("Test{newparam}");//Get a random number and convert it to a string, Newparam set the parameter to a random type, where you need to parameterize the settings strcat ( FileName, "c:/test/");//Save the path to the file variable strcat (filename,strnumber); Stitching file name strcat (filename, ". pdf");//concatenation suffix name, as required, complete the complete path and file name Web_set_max_html_param_len ("20000");//Set the maximum length of the parameter, Note that the value must be greater than the size of the file//Use the correlation function to get the contents of the downloaded file, where the left and right boundaries are not defined, and all the contents of the server response are obtained web_reg_save_param ("fcontent",///return contents are stored in fcontent this parameter " Lb= "," rb= "," Search=body ", last); Lr_start_transaction (" Download file ");   #设置的事务开始点 #web_url method you can write directly, you can also start recording, enter the download link URL for simple recording, mainly note the URL and resource these two parameters, Web_url ("file.php",       #函数名, no practical effect "url=http://forum.ubuntu.org.cn/download/file.php?id=129973&sid= 78fc8d76767ef49b606595824ceb963d ",     #下载链接, that is, the link entered into the browser will prompt the download, get a lot of methods;" Resource=1 "   # 1 means the download resource, 0 means the page resource "Reccontenttype=application/octetstream", "referer=", "Snapshot=t1.inf", last); Flen = Web_get_int_ Property (Http_info_download_size);//Gets the length of the file in the response if (Flen > 0) {             // Open File as Write filecontent = fopen (filename, "WB"), if (filecontent = = NULL)   #看是否正确打开了需要保存下载内容的文件, filename is the file path of the prepared organization; {lr_output_message ("Open file failed!"); return-1;} Fwrite (Lr_eval_string ("{fcontent}"), Flen, 1, filecontent);//write file Contents fclose (filecontent);//Close File}lr_end_transaction ( "Download File", Lr_auto); #事务结束点return 0;}

LoadRunner download File script

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.