Loadrunner之HTTP接口测试

  接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过程。测试http接口和测试webservice接口一样,需要开发提供相关接口及参数说明,当然如果条件不允许,我们也可以通过IE浏览器插件httpwatch或者火狐浏览器的firebug等工具来捕获操作中的参数传递情况。接口参数说明如下:

接口测试地址:/cas/login

请求报文参数说明:

请求报文格式:

<?xml version="1.0" encoding="ISO-8859-1"?>
< Publish >
  <SNSID>123</SNSID>
  <UserID>456</ UserID >
  <CommentsTypeID>2</ CommentsTypeID >
  <CommentsID>123</CommentsID>
  <AuthorID>456</AuthorID>
  <CommentsContent>Don't forget the meeting!</CommentsContent >
</Publish>

应答报文的参数接口说明:

<?xml version="1.0" encoding="ISO-8859-1"?>
< Publish >
  <UserID>456</ UserID >
  <CommentsTypeID>2</ CommentsTypeID >
  <CommentsID>123</CommentsID>
  <CommentsContent>Don't forget the meeting!</CommentsContent >
  <StatusCode>0</StatusCode>
  <StatusText>发送成功一条评论</StatusText>
</Publish>

 

根据文档的描述在LoadRunner书写相应的接口测试脚本。

一、使用web_submit_data()

web_submit_data("insert",
"Action=http://116.211.23.123/SNS/Publish.htm ",
"Method=POST", 
"Referer=http://116.211.23.123/SNS/Publish.htm ",
"Mode=HTML",
ITEMDATA,
"Name= SNSID ","Value=6601",ENDITEM,
"Name= UserID ","Value=123",ENDITEM,
"Name= CommentsTypeID ","Value=1",ENDITEM,
"Name= CommentsID ","Value=456",ENDITEM,
"Name= AuthorID","Value=789",ENDITEM,
"Name= CommentsContent ","Value=Just for testing",ENDITEM,
LAST);

二、使用web_custom_request()

char str[1000];
strcpy(str,"SNSID=7999&UserID=1&CommentsTypeID=1&CommentsID=1&AuthorID=1&CommentsContent=1");
web_custom_request("Publish",
"Url= http://116.211.23.123/SNS/Publish.htm",
"Method=POST",
"Referer=http://116.211.23.123/SNS/Publish.htm ",
"Mode=HTTP",
str,
LAST);

 

posted on 2015-12-31 11:02  TestWorld  阅读(2812)  评论(0编辑  收藏  举报