编写脚本常用的一些函数

上一篇 / 下一篇  2012-02-28 14:42:50 / 个人分类:loadRunner

一、web_submmit_data

 语法:
 Int web_submit_data ( const char *StepName, <List of Attributes>, ITEMDATA, <List of data>, [ EXTRARES, <List of Resource Attributes>,] LAST );

返回值
 返回LR_PASS0)代表成功,LR_FAIL1)代表失败。

如:

web_submit_data("UploadFile",
     "Action=http://{ip}/service/{user}.{email}/UploadFile?",---最新工作中犯的一个错,习惯性的把Action字段写成了URL,导致一直提示参数错误
     "Method=POST",
     "EncType=multipart/form-data",
     "RecContentType=application/json",
     "Mode=HTTP",
     ITEMDATA,
     "Name=path","Value=E:\\test\\{file_name}",ENDITEM,
     "Name=uploadFile","Value=E:\\test\\test.JPG","file=yes","ContentType=application/octet-stream",ENDITEM,
     "Name=replaceOldFile","Value=true",ENDITEM,
     "Name=createFolder","Value=true",ENDITEM,
     LAST);

----submit在提交的时候,不是提交地址,而是提交二进制流,所以不需要多一部把对应的文件转成二进制流。这点需要注意

二、intweb_add_auto_header(const char *Header, const char *Content ); ----给http请求增加一个header,我现解为更改了IE的一个属性

web_add_auto_header("Accept-Encoding","gzip;default");

三、intweb_get_int_property(const intHttpInfoType); 

参数属性:1.http_info_return_code:     返回http代码
2.http_info_download_size:返回页面字节数
3.http_info_download_time:返回页面下载时间

下载代码:---避免下载可能给测试机带来的压力,所以只判断下载的文件大小是否正确

int iflen;

 lr_start_transaction("DownloadFile");

 web_custom_request("DownloadFile",
  "URL=http://192.168.0.9:8080/service/test.1/download",
  "Method=get",
  "RecContentType=application/octet-stream",
  "EncType=text/plain; charset=utf-8",
  LAST);

 iflen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

 if(iflen>7000){
  lr_end_transaction("DownloadFile",LR_PASS);
 }else{
  lr_end_transaction("DownloadFile",LR_FAIL);
 }

四、strftime()---格式化时间,可以把时间格式化为我们想要的格式。原型:size_t *strftime (char *string, size_tmaxlen, const char *format, const struct tm *timestruct);

 long t,sTime;

int i;

i = rand()%100 + 1;
sTime = time(&t) - i*60*60; ---time(&t)取当前时间
strftime(startTime,1024,"%Y-%m-%d %H:%M:%S",localtime(&sTime));

TAG:

 

评分:0

我来说两句

日历

« 2024-04-29  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 15975
  • 日志数: 18
  • 建立时间: 2012-01-30
  • 更新时间: 2012-06-07

RSS订阅

Open Toolbar