Loadrunner模拟Json请求
作者:网络转载 发布时间:[ 2015/6/16 11:41:28 ] 推荐标签:性能测试工具
一、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.参数化脚本
运行脚本
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11