LoadRunner performance Test-download File script
Loadrunner Download File Script
Action()
{
intflen; //define an integer variable to hold the file size
longfiles; //save file handles
charfile[256]="\0"; //Save file path and file name
inttime ;
//Set the maximum number of bytes the page receives, which should be larger than the size of the download file, here 1MB
web_set_max_html_param_len("1024000");
//Use the correlation function to get the content of the downloaded file
web_reg_save_param_ex(
"ParamName=filecontent",
"LB=",
"RB=",
SEARCH_FILTERS,
"Scope=Body",
"RequestUrl=http://10.255.0.145/download.php? userId={userID}&bigmd5={userID}&offset=0",
LAST);
//download file
lr_start_transaction("download");
web_url("download",
"URL=http://10.255.0.145/download.php? userId={userID}&bigmd5={userID}&offset=0",
Resource=1",
"RecContentType=application/octet-stream",
"Referer=",
LAST);
lr_end_transaction("download",LR_AUTO);
/*web_get_int_property Returns the specific information of the previous http request, such as HTTP_INFO_DOWNLOAD_SIZE, HTTP_INFO_DOWNLOAD_TIME , HTTP_INFO_RETURN_CODE */
flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
lr_output_message("download file size is:%d",flen);
time=web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
lr_output_message("download time is:%d",time);
//Write the string "E:\\FSDownload\\%d.txt" to file
sprintf(file,"E:\\FSDownload\\%d.txt",rand());
lr_output_message("saved path:%s",file);
if(flen> 0){
if((filedes= fopen(file,"wb")) == NULL){
lr_output_message("OpenFile Failed! ", lr_eval_string("{filecontent}"));
return-1;
}
//write filecontent to the file pointed to by the files pointer, write flen once at a time
fwrite(lr_eval_string("{filecontent}"),flen,1,filedes);
fclose(filedes );
}
return0;
}