这三种方法分别在秦皇岛项目、鄂州项目中进行了使用,现将主要的内容进行整理(在此之前没有记录博客的习惯,是随便总结在了world中,其实还是很有必要记录下项目的具体情况以及自己在现场性能测试的情况,以便后续方便查阅)
1.1.1 方法1(web_service_call)
以秦皇岛健康卡项目接口测试为例进行详细说明
接口中传有三个参数:dylx=1","fwlx=s302"(代表查询居民信息),xmlString传的是xml形式入参内容。(需要将xml中的证件号码进行参数化,实际项目中需要参数化哪些内容需要和开发进行了解后在做处理)
(1)开发提供的接口格式为xml,访问地址为
(2)通过IE浏览并将结果另存为xml格式
(3)打开LR工具,协议选择webservice协议
(4)点击Manager Service,弹出窗口,点击Import输入要调用的接口地址
(5)点击Add Services弹出窗口,选择需要使用的方法,传入入参和出参的值
(6)点击ok后会形成代码
web_service_call( "StepName=patientRegister_102",
"SOAPMethod=PatientRegisterImplService|patientRegister|patientRegister",
"ResponseParam=response",
"Service=PatientRegisterImplService",
"ExpectedResponse=SoapResult",
"Snapshot=t1464838564.inf",
BEGIN_ARGUMENTS,
"dylx=1",
"fwlx=s302",
"xmlString=<root><head><serviceType>s302</serviceType><requestType>xml</requestType><version/><userName>zyyadmin</userName><password>000</password><orgCode>130302450070001</orgCode></head><body><parameter><zjlx>01</zjlx>"
"<zjhm>{zjhm}</zjhm><klx></klx><kh></kh></parameter></body></root>",
END_ARGUMENTS,
BEGIN_RESULT,
"patientRegisterResult=Param_patientRegisterResult1",(出参内容)
END_RESULT,
LAST);
//输出传出参数的内容
lr_log_message("result=%s",lr_eval_string("{Param_patientRegisterResult1}"));
(7)运行脚本查看LR控制台中是否正常输入出参的内容。
1.1.2 方法2 (http协议)
1、利用html方式发送请求,新建脚本时选择的协议是html协议,而非webservice协议。经过比较http方式的脚本并发数脚本可以达到很大。
2、以鄂州健康卡接口查询功能为例,接口访问地址为
,其中可以根据证件号码来进行查询,因此需要进行参数化
1、脚本示例如下
web_reg_save_param("Response","LB=", "RB=", LAST);
web_add_header("SOAPAction","\"\"");
//web_add_header("SOAPAction", "SampleMethod") 一样的效果
//开始事物
lr_start_transaction("REQ");
web_custom_request("hs_getHealthCardStatus","Method=POST", "Mode=HTML","RecContentType=text/xml","EncType=text/xml; charset=utf-8","URL=http://172.26.168.49:8080/rhcms-adapter-hs/service?wsdl","Body=<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.hs.adapter.rhcms.wn.com/\">"
"<soapenv:Header>"
"<requestHeader>"
"<samCardNum>42070020160317001002</samCardNum>"
"<orgCode>000000</orgCode>"
"<ip>192.168.64.101</ip>"
"<machineNum>UAI150710472</machineNum>"
"</requestHeader>"
"</soapenv:Header>"
"<soapenv:Body>"
"<ser:hs_getHealthCardStatus>"
"<healthCardNum>{cardnum}</healthCardNum>"
"</ser:hs_getHealthCardStatus>"
"</soapenv:Body>"
"</soapenv:Envelope>","last" );
//控制台打印出出参内容
lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
//结束事物
lr_end_transaction("REQ", LR_AUTO);
1.1.3 方法3 (soap import)
同样以鄂州项目为例,使用soap import方法实现
1、首先使用soupi验证xml文件是否可以通过服务器接口,如图已经通过,在xml文件中右击,另存为xml文件。
2、新建webservice协议,创建webservice脚本
3、import soap,找到xml所在的路径,点击load,并且输入url地址
4、点击ok,生成以下脚本
soap_request("StepName=SOAP Request",
"URL=http://172.26.168.49:8080/rhcms-adapter-hs/service?wsdl", "SOAPEnvelope=" "<wsdl:definitions xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"http://service.hs.adapter.rhcms.wn.com/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:ns1=\"http://schemas.xmlsoap.org/soap/http\" name=\"HealthCardServiceService\" targetNamespace=\"http://service.hs.adapter.rhcms.wn.com/\">" "<wsdl:types>" "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://service.hs.adapter.rhcms.wn.com/\" elementFormDefault=\"unqualified\" targetNamespace=\"http://service.hs.adapter.rhcms.wn.com/\" version=\"1.0\">" "<xs:element name=\"hs_getHealthCardStatus\" type=\"tns:hs_getHealthCardStatus\"></xs:element>" "<xs:element name=\"hs_getHealthCardStatusResponse\" type=\"tns:hs_getHealthCardStatusResponse\"></xs:element>" "<xs:complexType name=\"hs_getHealthCardStatus\">" "<xs:sequence>" "<xs:element minOccurs=\"0\" name=\"healthCardNum\" type=\"xs:string\"></xs:element>" "</xs:sequence>" "</xs:complexType>" "<xs:complexType name=\"hs_getHealthCardStatusResponse\">" "<xs:sequence>" "<xs:element minOccurs=\"0\" name=\"result\" type=\"tns:responseEntity\"></xs:element>" "</xs:sequence>" "</xs:complexType>" "<xs:complexType name=\"responseEntity\">" "<xs:complexContent>" "<xs:extension base=\"tns:abstractJsonEntity\">" "<xs:sequence>" "<xs:element minOccurs=\"0\" name=\"data\" type=\"xs:anyType\"></xs:element>" "</xs:sequence>" "</xs:extension>" "</xs:complexContent>" "</xs:complexType>" "<xs:complexType name=\"abstractJsonEntity\">" "<xs:sequence>" "<xs:element minOccurs=\"0\" name=\"code\" type=\"xs:string\"></xs:element>" "<xs:element minOccurs=\"0\" name=\"message\" type=\"xs:string\"></xs:element>" "</xs:sequence>" "</xs:complexType>" "<xs:complexType name=\"healthCardStatusResponse\">" "<xs:sequence>" "<xs:element minOccurs=\"0\" name=\"cardStatusCode\" type=\"xs:int\"></xs:element>" "<xs:element minOccurs=\"0\" name=\"cardStatusName\" type=\"xs:string\"></xs:element>" "</xs:sequence>" "</xs:complexType>" "</xs:schema>" "</wsdl:types>" "<wsdl:message name=\"hs_getHealthCardStatusResponse\">" "<wsdl:part element=\"tns:hs_getHealthCardStatusResponse\" name=\"parameters\"></wsdl:part>" "</wsdl:message>" "<wsdl:message name=\"hs_getHealthCardStatus\">" "<wsdl:part element=\"tns:hs_getHealthCardStatus\" name=\"parameters\"></wsdl:part>" "</wsdl:message>" "<wsdl:portType name=\"HealthCardService\">" "<wsdl:operation name=\"hs_getHealthCardStatus\">" "<wsdl:input message=\"tns:hs_getHealthCardStatus\" name=\"hs_getHealthCardStatus\"></wsdl:input>" "<wsdl:output message=\"tns:hs_getHealthCardStatusResponse\" name=\"hs_getHealthCardStatusResponse\"></wsdl:output>" "</wsdl:operation>" "</wsdl:portType>" "<wsdl:binding name=\"HealthCardServiceServiceSoapBinding\" type=\"tns:HealthCardService\">" "<soap:binding style=\"document\" transport=\"http://schemas.xmlsoap.org/soap/http\"></soap:binding>" "<wsdl:operation name=\"hs_getHealthCardStatus\">" "<soap:operation soapAction=\"\" style=\"document\"></soap:operation>" "<wsdl:input name=\"hs_getHealthCardStatus\">" "<soap:body use=\"literal\"></soap:body>" "</wsdl:input>" "<wsdl:output name=\"hs_getHealthCardStatusResponse\">" "<soap:body use=\"literal\"></soap:body>" "</wsdl:output>" "</wsdl:operation>" "</wsdl:binding>" "<wsdl:service name=\"HealthCardServiceService\">" "<wsdl:port binding=\"tns:HealthCardServiceServiceSoapBinding\" name=\"HealthCardServicePort\">" "<soap:address location=\"http://172.26.168.49:8080/rhcms-adapter-hs/service\"></soap:address>" "</wsdl:port>" "</wsdl:service>" "</wsdl:definitions>", "SOAPAction=", "ResponseParam=response", "Snapshot=t1465958871.inf", LAST);5、并对对应的字段进行参数化
总结:刚结合项目做性能时,除了向开发了解相应的情况外,剩下就是度娘,确实帮助很多。在实际操作过程中会遇到很多问题并且自己也会开始探索各种各样的方法去尝试。没有人带,所有的一切都是一个摸索的过程。参考文献:https://wenku.baidu.com/view/c10647738e9951e79b89277f.html?qq-pf-to=pcqq.c2c