Today, I used LoadRunner to download files on the web site. First, I learnedArticle(Use LoadRunner to download the file and save it locally) write a script. After running the script, it is found that the download of the binary file type (such as RAR and BMP) is normal, however, there is a problem with the types of text files (such as TXT and XML). The problem lies in the judgment of the file size.
In the guanhe scriptFLEN = web_get_int_property (http_info_download_size );To obtain the size of the object to be downloaded.
For binary files, run logs:
Web_link ("aa.bmp") highest severity level was "warning", 824 body bytes, 197 header bytes
FLEN: 1021
The file size is 1021 bytes, including the header of 197 bytes and the body of 824 bytes.
For text files, run logs:
Web_link ("test. xml") was successful, 277 body bytes, 203 header bytes
FLEN: 480
The size of the downloaded file is 480 bytes, including the body of 227 bytes and header of 203 bytes. An error occurred while opening the XML file.In fact, the actual file size is 227 bytes, which is the body part.
Modified the script and changed the statement for getting the file size aboveFLEN = strlen (lr_eval_string ("{fcontent }"));, Only take the body part as the file content, and the result will be OK.
Run log:
Web_link ("test. xml") was successful, 277 body bytes, 203 header bytes
FLEN: 277
However, this method cannot be used to correctly download binary files. It is estimated that this method cannot be used to obtain the file size. Currently, there is no perfect combination of methods. I hope some friends can give me some advice.
The script is as follows:
Action ()
{
Int FLEN;
Long Filedes;
Char Filename [ 1024 ];
Web_add_cookie ( " Seraph. OS. Cookie = elklhkqmjlokfjgjji; domain = 172.20.16.4 " );
Web_set_max_html_param_len ( " 1024000 " );
Web_url ( " 172.20.16.4: 8080 " ,
" Url = http: // 172.20.16.4: 8080/ " ,
" Resource = 0 " ,
" Reccontenttype = text/html " ,
" Referer = " ,
" Snapshot = t4.inf " ,
" Mode = html " ,
Extrares,
" Url =/styles/global.css " , " Referer = http: // 172.20.16.4: 8080/secure/dashboard. JSpA " , Enditem,
Last );
Web_link ( " Test-306 " ,
" TEXT = test-306 " ,
" Snapshot = t5.inf " ,
Extrares,
" Url = ../styles/global.css " , Enditem,
Last );
Web_reg_save_param ( " Fcontent " , " Lb = " , " RB = " , " Search = body " , Last );
Web_link ( " Test. xml " ,
" TEXT = test. xml " ,
" Snapshot = t6.inf " ,
Last );
// Obtains the size of a text file.
FLEN = Strlen (lr_eval_string ( " {Fcontent} " ));
// Obtains the size of a binary file.
// FLEN = web_get_int_property (http_info_download_size );
Lr_message ( " ----------------- FLEN: % d " , FLEN );
// Generate random file names to facilitate concurrency
Strcpy (filename, " D: \ 123 \ AA _ " );
Strcat (filename, lr_eval_string ( " {Num} " ));
Strcat (filename, " . Xml " );
If (FLEN > 0 )
{
// Open a file in write mode
If (Filedes = Fopen (filename, " 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 );
}
Return 0 ;
}