LoadRunner模拟REST接口的json请求

发表于:2015-5-12 11:01

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:performanceTest    来源:51Testing软件测试网采编

  现在很多手机应用的性能测试,REST接口调用通过json格式,在用loadrunner模拟这些json请求时,需要开发提供
  1、供接口地址
  2、提交方式(get、post、put)
  3、消息体(消息在loadrunner里面遇到特殊字符注意使用转义)
  获取这些信息后就可以用loadrunner模拟请求了,demo如下:
Action()
{
lr_think_time(1);
lr_start_transaction("mnp_mock");
web_reg_save_param("response",
"LB=1.1",
"RB=OK",
"Ord=1",
"Search=ALL",
"Notfound=warning",
LAST);
web_custom_request("upload",
"URL=http://IP:port/api/api/v1/service/push",
"Method=POST",
"TargetFrame=",
"Resource=1",
"Referer=",
"Mode=HTML",
"EncType=application/json",
"Body={\"messageID\":{messageID},\"groupID\":null,\"content\":\"redis putmessage1\",\"remark\":\"20001remark\",\"devices\":[{\"messageID\":\"{messageID}\",\"userID\":\"{userID}\",\"deviceID\":\"{deviceID}\",\"deviceType\":\"{deviceType}\",\"deviceToken\":\"admkmd121\",\"deviceOS\":\"121os\"},{\"messageID\":\"{messageID}\",\"userID\":\"{userID}\",\"deviceID\":\"{deviceID}\",\"deviceType\":\"{deviceType}\",\"deviceToken\":\"admkmd122\",\"deviceOS\":\"122os\"}]}",
LAST);
if (atoi(lr_eval_string("{response}"))>0)
{
lr_end_transaction("mnp_mock",LR_PASS);
}
else
{
lr_end_transaction("mnp_mock",LR_FAIL);
//lr_error_message("%s",lr_eval_string("{response}"));
}
return 0;
}
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号