LoadRunner download file script
Action ()
{
Intflen; // define an integer variable to save and obtain the file size
Longfiledes; // save the file handle
Charfile [256] = "\ 0"; // save the file path and file name
Inttime;
// Set the maximum number of bytes received on the page. This setting should be larger than the size of the downloaded file. The value here is 1 MB.
Web_set_max_html_param_len ("1024000 ");
// Use the correlated function to obtain the downloaded object content
Web_reg_save_param_ex (
"Paramname = filecontent ",
"LB = ",
"RB = ",
Search_filters,
"Scope = body ",
"Requesturl = http: // 10.20.0.145/download. php? Userid = {userid} & bigmd5 = {userid} & offset = 0 ",
Last );
// Download an object
Lr_start_transaction ("Download ");
Web_url ("Download ",
"Url = http: // 10.20.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: % d", FLEN );
Time = web_get_int_property (http_info_download_time );
Lr_output_message ("download time: % 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 by the filedes pointer, write FLEN each time, write once
Fwrite (lr_eval_string ("{filecontent}"), FLEN, 1, filedes );
Fclose (filedes );
}
Return0;
}
This article is from the "Swallow swallow test column" blog, please be sure to keep this source http://bobbleyan.blog.51cto.com/9111528/1568505
LoadRunner Performance Test-download file script