• Loadrunner上传文件与下载文件脚本


    Loadrunner上传与下载文件脚本

    一、 上传脚本

    Action()
    {
    int uploadImgStatus = 0;
      //获取上传产品图ID
    web_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]=""; 
    
    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;
    
    }
  • 相关阅读:
    17、Semantic-UI之分页插件
    16、Semantic-UI之模态窗口
    15、Semantic-UI之导航
    14、Semantic-UI之菜单样式
    13、Semantic-UI之表格与表单
    12、Semantic-UI之输入框
    11、Semantic-UI之分割线
    10、Semantic-UI之图片的使用
    9、Semantic-UI之标题
    8、Semantic-UI之其他按钮样式
  • 原文地址:https://www.cnblogs.com/igubai/p/7499273.html
Copyright © 2020-2023  润新知