溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

LoadRunner性能測試-下載文件腳本

發(fā)布時間:2020-07-21 22:57:38 來源:網(wǎng)絡(luò) 閱讀:1692 作者:qinyan20121209 欄目:軟件技術(shù)

Loadrunner下載文件腳本

 

Action()

{

         intflen;   //定義一個整型變量保存獲得文件的大小

         longfiledes; //保存文件句柄

         charfile[256]="\0"; //保存文件路徑及文件名

         inttime ;

 

//設(shè)置頁面接收最大的字節(jié)數(shù),該設(shè)置應(yīng)大于下載文件的大小,此處為1MB

         web_set_max_html_param_len("1024000");

 

//使用關(guān)聯(lián)函數(shù)獲取下載文件的內(nèi)容

         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);

 

  //下載文件

         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返回上一個http請求的具體信息,如HTTP_INFO_DOWNLOAD_SIZE, HTTP_INFO_DOWNLOAD_TIME , HTTP_INFO_RETURN_CODE */

 

                 flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);     

                 lr_output_message("下載文件大小是:%d",flen);

                 time=web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);

                 lr_output_message("下載時間是:%d",time);

                  

                 //把“E:\\FSDownload\\%d.txt”這個字符串寫到file

                 sprintf(file,"E:\\FSDownload\\%d.txt",rand());

                 lr_output_message("保存的路徑:%s",file);

 

               if(flen> 0){

                 if((filedes= fopen(file,"wb")) == NULL){

                    lr_output_message("OpenFile Failed!", lr_eval_string("{filecontent}"));

                                     return-1;

                  }

                  

                //filecontent寫到filedes指針指向的文件中,每次寫flen,寫1

                fwrite(lr_eval_string("{filecontent}"),flen,1,filedes);

                fclose(filedes );

              }

         return0;

}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI