LoadRunner测试WebService接口

Wicrecend 2012-08-23

LoadRunner测试WebService接口  

2010-06-06 10:30:52|  分类: LoadRunner|字号 订阅

方法一:使用LR自带的webservice协议,按照向导的提示:导入wsdl、选择服务名、形成脚本的框架、读懂并设定参数值,参照log返回信息,调试脚本........

方法二:利用LR的web(http/html)协议自带的web_custom_request()函数,向指定的URL地址POST相应的SOAP协议的HTTP消息。

下面首先给出根据wsdl文件生成SOAP消息的方法,然后给出函数示例:

根据wsdl文件生成SOAP消息可以借助工具XMLSpy这类的工具,它通过导入wsdl文件,建立相应服务的SOAP请求,示例如下:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<SOAP-ENV:Body>

<m:resetPasswordxmlns:m="http://www.mbossuac.com.cn/ua"SOAP-ENV:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">

<requestxsi:type="xsd:string">String</request>

</m:resetPassword>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

说明:String就是要POST给服务器的请求消息,不过在POST的时候要加上<![CDATA[]>标志;平时我们在做WebService接口的功能测试时,也可以使用XMLSpy工具,按照上述方法生成SOAP请求,然后直接发送请求给服务器,查看返回结果即可。

下面给出函数示例:

 lr_save_string("http://133.0.175.26:9300/services/CrmInterfaces?wsdl", "uacenter");

 web_add_header("SOAPAction","\"\"");

  web_reg_save_param("rspcode1", 

"LB=RspCode&gt;",

"RB=&lt;/RspCode",

"Ord=1",

"Search=body",

"RelFrameId=1",

     LAST);

 lr_start_transaction("resetPassword");

 //web_set_timeout("CONNECT", "3");

 web_custom_request("resetPassword", 

"URL={uacenter}",

"Method=POST",

"Resource=0",

"RecContentType=text/xml",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

"EncType=text/xml",

"Body=<soapenv:Envelopexmlns:soapenv="

"\"http://schemas.xmlsoap.org/soap/envelope/\"xmlns:ua="

"\"http://www.mbossuac.com.cn/ua\"><soapenv:Header/><soapenv:Body><ua:resetPassword>"

"<request><![CDATA[<?xmlversion=\"1.0\"?><CAPRoot><SessionHeader><ServiceCode>"

"CAP04009</ServiceCode><Version>CAP0400920091224</Version><ActionCode>"

"0</ActionCode><TransactionID>{TranId}</TransactionID><SrcSysID>"

"18103</SrcSysID><DstSysID>18</DstSysID><ReqTime>20100504125415</ReqTime>"

"<DigitalSign></DigitalSign></SessionHeader><SessionBody><ResetPassword>"

"<AccountType>2000004</AccountType>"

"<AccountID>{accountid1}</AccountID>"

"<NewPassword>654321</NewPassword>"

"<CertificateNo>{CertificateNo1}</CertificateNo>"

"<RegionId>1017</RegionId><Areacode>0719</Areacode>"

"</ResetPassword></SessionBody></CAPRoot>]"

"]></request></ua:resetPassword></soapenv:Body></soapenv:Envelope>"

"",

       LAST);

 lr_end_transaction("resetPassword", LR_AUTO);

// if(strcmp(lr_eval_string("{rspcode2}") ,"0000") && strcmp(lr_eval_string("{rspcode2}") ,"7004")) {

if(strcmp(lr_eval_string("{rspcode1}"),"0000")){

lr_error_message("resetPasswordfail:%s,%s,%s",lr_eval_string("{rspcode1}"),lr_eval_string("{accountid1}"));

 }

ps:在<![CDATA]>标记下,所有的标记、实体引用都被忽略,而被XML处理程序一视同仁地当做字符数据看待。

相关推荐