標籤:set nload 檔案大小 erer string turn blog erro item
Loadrunner上傳與下載檔案指令碼
一、 上傳指令碼
Action(){int uploadImgStatus = 0; //擷取上傳產品圖IDweb_reg_save_param_ex("ParamName=imgRandName","LB=\"sourceImgPath\":\"upload\\/cropzoomimg\\/","RB=\"}",LAST);uploadImgStatus = web_submit_data("CropZoomImgController.do","Action=http://192.168.2.67:7001/CropZoomImgController.do?method=uploadSourceImg","Method=POST","EncType=multipart/form-data","Referer=http://192.168.2.67:7001/GoodsController.do?method=toCreateGoods","Snapshot=t377.inf","Mode=HTTP",ITEMDATA,"Name=attachFile", "Value=G:\\123.txt", "File=Yes", ENDITEM,LAST);if (uploadImgStatus == 1) { //如果上傳失敗則終止指令碼lr_abort();lr_error_message("上傳失敗!");} else { //輸出上傳圖片ID(調試使用)lr_output_message("%s", lr_eval_string("{imgRandName}"));}return 0;}
二、下載指令碼
Action(){//定義一個整型變數儲存獲得檔案的大小int flen; //儲存檔案控制代碼long filedes; //儲存檔案路徑及檔案名稱char file[256]="\0"; char * chNumber ;int time;//設定頁面接收最大的位元組數,該設定應大於下載檔案的大小web_set_max_html_param_len("1024000"); //並發開始web_concurrent_start(NULL);//使用關聯函數擷取下載檔案的內容web_reg_save_param("filecontent","LB=","RB=","Search=BODY",LAST); web_url("android.apk",//下載連結"URL=http://res.t.ifeng.com/download/android/ifeng_weibo_android_v1.01beta.apk","Resource=1","RecContentType=application/force-download","Referer=",LAST);//並髮結束web_concurrent_end(NULL); //獲得下載檔案大小flen =web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); time=web_get_int_property (HTTP_INFO_DOWNLOAD_TIME);lr_output_message("下載時間是%d",time);//產生隨機數chNumber=lr_eval_string("{NewParam}"); //將下載檔案要儲存的路徑存到file裡strcat(file,"F:\\file");//在檔案名稱後自動產生隨機數strcat(file,chNumber);//下載的檔案尾碼名稱strcat(file,".apk");if(flen > 0){if((filedes = fopen(file,"wb")) == NULL){lr_output_message("Open FileFailed!", lr_eval_string("{filecontent}"));return -1;}fwrite(lr_eval_string("{filecontent}"),flen,1,filedes );fclose( filedes );}return 0;}
Loadrunner上傳檔案與下載檔案指令碼