LoadRunner模拟REST接口的json请求

  现在很多应用的,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;
}
 
 
转自:http://www.51testing.com/html/18/n-2441718.html
05-11 20:24