温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

LoadRunner性能测试-下载文件脚本

发布时间:2020-07-21 22:57:38 来源:网络 阅读:1683 作者:qinyan20121209 栏目:软件技术

Loadrunner下载文件脚本

 

Action()

{

         intflen;   //定义一个整型变量保存获得文件的大小

         longfiledes; //保存文件句柄

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

         inttime ;

 

//设置页面接收最大的字节数,该设置应大于下载文件的大小,此处为1MB

         web_set_max_html_param_len("1024000");

 

//使用关联函数获取下载文件的内容

         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问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI