Loadrunner模拟Json请求

发表于:2015-6-16 11:30  作者:乄動聽縼葎ヤ   来源:51Testing软件测试网采编

字体: | 上一篇 | 下一篇 |我要投稿 | 推荐标签: 性能测试 性能测试工具 软件测试工具 LoadRunner

  一、loadrunner脚本创建
  1.Insert - New step -选择Custom Request - web_custom_request
  2.填入相应参数
  3.生成脚本,并修改如下(参数中的引号"前需要加斜杠\转译)
Action()
{
lr_start_transaction("Sendorder");
web_reg_find("Search=Body",
"SaveCount=Sendorder_count",
"Text=ord_sn",
LAST);
web_custom_request("sendOrder.html",
"URL=http://192.168.1.205:9000/default/com.bybon.O2O.services.apiservice.getApiServiceMgr.getApiService.api",
"Method=POST",
"Resource=0",
"RecContentType=text/html",
"Referer=http://192.168.1.205:9000/default/com.bybon.O2O.services.apiservice.getApiServiceMgr.getApiService.api",
"Snapshot=t229.inf",
"Mode=HTTP",
"EncType=application/json",
"Body={\"sign\":\"963a8d91fab997a490918ebbfe71cba5\",\"param\":\"%7B%22ord_sn%22%3A%22%22%2C%22serve_type%22%3A%221%22%2C%22ord_platform%22%3A%22pcf%22%2C%22ord_src%22%3A%221%22%2C%22mem_id%22%3A%221905%22%2C%22wx_field%22%3A%22%22%2C%22mem_name%22%3A%2218551625706%22%2C%22zipcode%22%3A%22%22%2C%22postscript%22%3A%22%5Cu7559%5Cu8a00%22%2C%22tel%22%3A%2218551625706%22%2C%22email%22%3A%22%22%2C%22storecode%22%3A%22A042%22%2C%22sn%22%3A%22%22%2C%22imei%22%3A%22%22%2C%22phone_modelcode%22%3A%22080111%22%2C%22phone_color%22%3A%221%22%2C%22phone_volume%22%3A%222%22%2C%22suggest_scheme_code%22%3A%22080111.1.2.14.1%22%2C%22addressList%22%3A%5B%7B%22addr_type%22%3A%224%22%2C%22province%22%3A%222%22%2C%22city%22%3A%2252%22%2C%22district%22%3A%22506%22%2C%22address%22%3A%22test%22%2C%22zipcode%22%3A%22%22%2C%22tel%22%3A%2218551625706%22%2C%22user_name%22%3A%22%5Cu6d4b%5Cu8bd5%22%7D%5D%2C%22remark%22%3A%22%22%2C%22offerList%22%3A%22%22%2C%22appoint_stime%22%3A%222015-06-01+17%3A00%3A00%22%2C%22appoint_etime%22%3A%222015-06-01+19%3A00%3A00%22%2C%22bill_receiver_name%22%3A%22%22%2C%22bill_tel%22%3A%22%22%2C%22bill_province_name%22%3A%22%22%2C%22bill_city_name%22%3A%22%22%2C%22bill_area_name%22%3A%22%22%2C%22bill_address%22%3A%22%22%2C%22bill_title%22%3A%22%22%2C%22bill_company_name%22%3A%22%22%2C%22cnfdet_flag%22%3A2%7D\",\"svcCode\":\"EC013\",\"msgSrc\":\"SDFPHP\"}",
LAST);
if(strcmp(lr_eval_string("{Sendorder_count}"),"0")==0)
{
lr_end_transaction("Sendorder",LR_FAIL);
return0;
}
else
{
lr_end_transaction("Sendorder",LR_PASS);
}
return0;
}
  4.捕获页面返回值
  返回格式{"code":"0","msg":"%E6%88%90%E5%8A%9F","data":{"ord_sn":"9000003486"}}
  将光标移动到脚本顶部,插入关联点insert-new step-service-web_reg_save_param
  在脚本顶部,插入并修改脚本如下
  web_reg_save_param("user_tags",
  "LB=ord_sn\":\"",
  "RB=\"]}",
  LAST);
  在脚本尾部,加入输出日志验证是否获取成功
  lr_message ("user_tags:%s", lr_eval_string("{user_tags}"));
  5.对我们的接口做自动化功能测试,写验证脚本如下:
  if (atoi(lr_eval_string("{user_tags}"))==0)
  lr_output_message("user_tags:%s,succeed!",(lr_eval_string("{user_tags}")));
  else if(atoi(lr_eval_string("{user_tags}"))==1)
  lr_output_message("user_tags:%s,failed!",(lr_eval_string("{user_tags}")));
  else
  lr_output_message("user_tags:%s,unknow!",(lr_eval_string("{user_tags}")));
  6.参数化脚本
  运行脚本

【福利】填问卷送精选测试礼包+接口测试课程!为测试行业做点事!
21/212>

评 论

论坛新帖

顶部 底部


建议使用IE 6.0以上浏览器,800×600以上分辨率,法律顾问:上海瀛东律师事务所 张楠律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2020, 沪ICP备05003035号
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪公网安备 31010102002173号

51Testing官方微信

51Testing官方微博

扫一扫 测试知识全知道