美文网首页
loadrunner录制下载文件脚本

loadrunner录制下载文件脚本

作者: 认真点啊 | 来源:发表于2018-06-04 10:19 被阅读0次

    loadrunner指定文件-PDF下载到本地

    Action()
    {
        int flen; //定义一个整型变量保存获得文件的大小 
        long filedes; //保存文件句柄 
    
        web_set_max_html_param_len("2000000");//设置页面接收最大的字节数,该设置应大于下载文件的大小
    
        //filecontent 获取下载文件的内容
        //使用关联函数获取下载文件的内容,在这里不定义左右边界,获得服务器响应的所有内容
        web_reg_save_param("filecontent",
                   "LB=",
                   "RB=",
                   "Search=BODY",
                   LAST);
    
        //使用关联函数在服务器响应的头文件中获取下载文件名
    
        lr_start_transaction("download_certificate");
    
        //发送下载文件的请求
        web_url("downloadPdf.do",
        
        "URL=https://www.trusted-cn.com/czy/certificate/certificatelist/downloadPdf.do?certificateId=fb1e6069e2964c62bc17cd7ecf77ba73",
        
        "Resource=0",
        
        "RecContentType=application/pdf",
    
        "Snapshot=t3.inf",
    
        "Referer=https://www.trusted-cn.com/czy/certificate/certificatelist/list.do?section=1&mdCode=certificate&type=1&menuId=ff808181617eef1501617ef99c130008",
        
        LAST);
    
        //获取响应文件的长度
        flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
        lr_output_message("%d",flen);
    
        
        if(flen > 0) 
        {
              //将文件下载至指定目录,文件名称是根据实际返回数据获取
            if((filedes = fopen("c://DownloadFiles//XXXX.pdf","wb")) == NULL) 
            {
            
            lr_output_message("Open File Failed!");
            
            return -1;
            
            }
            //写入文件内容
            fwrite( lr_eval_string("{filecontent}"),flen,1,filedes );
            
            fclose( filedes );
        
        }
    
        lr_end_transaction("download_certificate",LR_AUTO);
    
        return 0;
    }
    
    

    具体参考:http://www.cnblogs.com/baihuitestsoftware/articles/6406190.html

    相关文章

      网友评论

          本文标题:loadrunner录制下载文件脚本

          本文链接:https://www.haomeiwen.com/subject/qdresftx.html