今天简单给需要用的朋友们介绍下LR11的webservice协议脚本脚本实现的三种形式:
方式1:webservice协议脚本_souprequest方式脚本_方法不太好返回值为乱码(因为是基于utf-8的)
LR11相关代码如下:
Action()
{
soap_request("StepName=SOAP Request",
"URL=http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx",
"SOAPEnvelope="
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\">"
"<mobileCode>13770321511</mobileCode>"
"<userID></userID>"
"</getMobileCodeInfo>"
"</soap:Body>"
"</soap:Envelope>",
"SOAPAction=http://WebXml.com.cn/getMobileCodeInfo",
"ResponseParam=response",
"Snapshot=t1528944893.inf",
LAST);
lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg1");
lr_output_message(lr_eval_string("{msg1}"));
return 0;
}
回显如下:
LOCAL start date/time: 2018-06-14 11:03:29
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(4): SOAP request "SOAP Request" started
Action.c(4): t=1792ms: 277-byte response headers for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(4): HTTP/1.1 200 OK\r\n
Action.c(4): Cache-Control: private, max-age=0\r\n
Action.c(4): Content-Type: text/xml; charset=utf-8\r\n
Action.c(4): Content-Encoding: gzip\r\n
Action.c(4): Vary: Accept-Encoding\r\n
Action.c(4): Server: Microsoft-IIS/7.5\r\n
Action.c(4): X-AspNet-Version: 2.0.50727\r\n
Action.c(4): X-Powered-By: ASP.NET\r\n
Action.c(4): Date: Thu, 14 Jun 2018 03:03:35 GMT\r\n
Action.c(4): Content-Length: 390\r\n
Action.c(4): \r\n
Action.c(4): t=1838ms: 390-byte ENCODED response body received for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(4): t=1843ms: 437-byte DECODED response body for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(4): <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
Action.c(4): g/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
Action.c(4): www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.
Action.c(4): cn/"><getMobileCodeInfoResult>13770321511锛氭睙鑻\x8F 鍗椾含 姹熻嫃绉诲姩鍔ㄦ劅鍦板甫鍗\xA1
Action.c(4): </getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>
Action.c(4): Notify: Saving Parameter "response = <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>13770321511锛氭睙鑻\x8f 鍗椾含 姹熻嫃绉诲姩鍔ㄦ劅鍦板甫鍗\xa1</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>".
Action.c(4): SOAP request "SOAP Request" was successful
Action.c(19): Notify: Parameter Substitution: parameter "response" = "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>13770321511锛氭睙鑻\x8f 鍗椾含 姹熻嫃绉诲姩鍔ㄦ劅鍦板甫鍗\xa1</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>"
Action.c(19): Notify: Saving Parameter "msg1 = <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>13770321511:江苏 南京 江苏移动动感地带卡</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>\x00".
Action.c(21): Notify: Parameter Substitution: parameter "msg1" = "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>13770321511:江苏 南京 江苏移动动感地带卡</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>\x00"
Action.c(21): <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>13770321511:江苏 南京 江苏移动动感地带卡</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
方法2:webservice协议脚本_web_custom_request_很差的方法
Action()
{
web_custom_request("getweather",
"URL=http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx",
"Method=POST",
"Resource=0",
"RecContentType=text/xml",
"Mode=HTML",
"Enctype=text/xml;charset=uft-8",
"Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\">"
"<mobileCode>13770321511</mobileCode>"
"<userID></userID>"
"</getMobileCodeInfo>"
"</soap:Body>"
"</soap:Envelope>",
LAST);
return 0;
}
回显如下:
Virtual User Script started at : 2018-06-14 11:44:16
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8859 (Aug 18 2010 20:14:31) [MsgId: MMSG-27143]
Run Mode: HTML [MsgId: MMSG-26000]
Run-Time Settings file: "C:\Users\dell\AppData\Local\Temp\noname11\\default.cfg" [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(3): t=1532ms: 277-byte response headers for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(3): HTTP/1.1 200 OK\r\n
Action.c(3): Cache-Control: private, max-age=0\r\n
Action.c(3): Content-Type: text/xml; charset=utf-8\r\n
Action.c(3): Content-Encoding: gzip\r\n
Action.c(3): Vary: Accept-Encoding\r\n
Action.c(3): Server: Microsoft-IIS/7.5\r\n
Action.c(3): X-AspNet-Version: 2.0.50727\r\n
Action.c(3): X-Powered-By: ASP.NET\r\n
Action.c(3): Date: Thu, 14 Jun 2018 03:44:22 GMT\r\n
Action.c(3): Content-Length: 390\r\n
Action.c(3): \r\n
Action.c(3): t=1609ms: 390-byte ENCODED response body received for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(3): t=1617ms: 437-byte DECODED response body for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(3): <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
Action.c(3): g/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
Action.c(3): www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.
Action.c(3): cn/"><getMobileCodeInfoResult>13770321511锛氭睙鑻\x8F 鍗椾含 姹熻嫃绉诲姩鍔ㄦ劅鍦板甫鍗\xA1
Action.c(3): </getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>
Action.c(3): web_custom_request("getweather") was successful, 390 body bytes, 277 header bytes [MsgId: MMSG-26386]
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
方式3:webservice协议脚本_web_service_call方式开发脚本(方法优秀简单)
LR11代码如下:
Action()
{
lr_rendezvous("开始");
lr_start_transaction("事件开始");
web_service_call( "StepName=getMobileCodeInfo_102",
"SOAPMethod=MobileCodeWS|MobileCodeWSSoap|getMobileCodeInfo",
"ResponseParam=response",
"Service=MobileCodeWS",
"ExpectedResponse=SoapResult",
"Snapshot=t1528884495.inf",
BEGIN_ARGUMENTS,
"mobileCode=130163013352",
"userID=",
END_ARGUMENTS,
BEGIN_RESULT,
"getMobileCodeInfoResult=Param_getMobileCodeInfoResult",
END_RESULT,
LAST);
if ((strstr(lr_eval_string("{Param_getMobileCodeInfoResult}") ,"广东 珠海 广东联通GSM卡"))==NULL)
{
lr_error_message("--------%s",lr_eval_string("{Param_getMobileCodeInfoResult}"));
lr_end_transaction("事件开始", LR_FAIL);
}
else
{
lr_output_message("-------%s",lr_eval_string("{Param_getMobileCodeInfoResult}"));
lr_end_transaction("事件开始", LR_PASS);
}
return 0;
}
回显清晰明了没有多余函数及乱码:
Virtual User Script started at : 2018-06-14 09:49:30
Starting action vuser_init.
Web Services replay version 11.0.0 for Windows 7; Toolkit: ".Net"; build 8859
Run-Time Settings file: "C:\Users\dell\AppData\Local\Temp\noname11\\default.cfg"
Vuser directory: "C:\Users\dell\AppData\Local\Temp\noname11"
Vuser output directory: "C:\Users\dell\AppData\Local\Temp\noname11\"
LOCAL start date/time: 2018-06-14 09:49:30
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(4): Notify: Transaction "事件开始" started.
Action.c(6): Web service call "getMobileCodeInfo_102" started
Action.c(6): "SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"" header registered for adding to requests from the immediately following Action function [MsgId: MMSG-26506]
Action.c(6): "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.2032)" header registered for adding to requests from the immediately following Action function [MsgId: MMSG-26506]
Action.c(6): "Content-Type: text/xml; charset=utf-8" header registered for adding to requests from the immediately following Action function [MsgId: MMSG-26506]
Action.c(6): t=3385ms: Connecting [0] to host 61.147.124.120:80 [MsgId: MMSG-26000]
Action.c(6): t=3390ms: Connected socket [0] from 10.2.89.219:32221 to 61.147.124.120:80 in 3 ms [MsgId: MMSG-26000]
Action.c(6): t=3393ms: 376-byte request headers for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(6): POST /WebServices/MobileCodeWS.asmx HTTP/1.1\r\n
Action.c(6): Content-Type: text/xml; charset=utf-8\r\n
Action.c(6): Cache-Control: no-cache\r\n
Action.c(6): SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"\r\n
Action.c(6): User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.20
Action.c(6): 32)\r\n
Action.c(6): Accept-Encoding: gzip, deflate\r\n
Action.c(6): Accept: */*\r\n
Action.c(6): Connection: Keep-Alive\r\n
Action.c(6): Host: www.webxml.com.cn\r\n
Action.c(6): Content-Length: 773\r\n
Action.c(6): \r\n
Action.c(6): t=3452ms: 773-byte request body for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(6): <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
Action.c(6): g/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
Action.c(6): www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"><s
Action.c(6): oap:Header><wsa:Action>http://WebXml.com.cn/getMobileCodeInfo</wsa:Action><wsa:MessageID>u
Action.c(6): uid:c8e01b64-6a9b-4af7-8fd2-f1d944e7fab3</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://s
Action.c(6): chemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address></wsa:ReplyTo><wsa:To
Action.c(6): >http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx</wsa:To></soap:Header><soap:Body><
Action.c(6): getMobileCodeInfo xmlns="http://WebXml.com.cn/"><mobileCode>130163013352</mobileCode><user
Action.c(6): ID /></getMobileCodeInfo></soap:Body></soap:Envelope>
Action.c(6): t=5029ms: 277-byte response headers for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(6): HTTP/1.1 200 OK\r\n
Action.c(6): Cache-Control: private, max-age=0\r\n
Action.c(6): Content-Type: text/xml; charset=utf-8\r\n
Action.c(6): Content-Encoding: gzip\r\n
Action.c(6): Vary: Accept-Encoding\r\n
Action.c(6): Server: Microsoft-IIS/7.5\r\n
Action.c(6): X-AspNet-Version: 2.0.50727\r\n
Action.c(6): X-Powered-By: ASP.NET\r\n
Action.c(6): Date: Thu, 14 Jun 2018 01:49:39 GMT\r\n
Action.c(6): Content-Length: 376\r\n
Action.c(6): \r\n
Action.c(6): t=5126ms: 376-byte ENCODED response body received for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(6): t=5130ms: 429-byte DECODED response body for "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" (RelFrameId=1, Internal ID=1)
Action.c(6): <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
Action.c(6): g/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
Action.c(6): www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.
Action.c(6): cn/"><getMobileCodeInfoResult>130163013352锛氬箍涓\x9C 鐝犳捣 骞夸笢鑱旈\x80欸SM鍗\xA1</ge
Action.c(6): tMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>
Action.c(6): t=5153ms: Request done "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx" [MsgId: MMSG-26000]
Action.c(6): Notify: Saving Parameter "getMobileCodeInfo_102_Response = <getMobileCodeInfo><getMobileCodeInfoResult>130163013352:广东 珠海 广东联通GSM卡</getMobileCodeInfoResult></getMobileCodeInfo>".
Action.c(6): Notify: Saving Parameter "response = <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>130163013352锛氬箍涓\x9c 鐝犳捣 骞夸笢鑱旈\x80欸SM鍗\xa1</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>".
Action.c(6): Notify: Saving Parameter "Param_getMobileCodeInfoResult = 130163013352:广东 珠海 广东联通GSM卡".
Action.c(6): Web service call "getMobileCodeInfo_102" was successful
Action.c(20): Notify: Parameter Substitution: parameter "Param_getMobileCodeInfoResult" = "130163013352:广东 珠海 广东联通GSM卡"
Action.c(28): Notify: Parameter Substitution: parameter "Param_getMobileCodeInfoResult" = "130163013352:广东 珠海 广东联通GSM卡"
Action.c(28): -------130163013352:广东 珠海 广东联通GSM卡
Action.c(29): Notify: Transaction "事件开始" ended with "Pass" status (Duration: 3.8570 Wasted Time: 2.0035).
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
t=5343ms: Closed connection [0] to www.webxml.com.cn:80 after completing 1 request [MsgId: MMSG-26000]
以上三种webservice不同方式实现脚本已提供给大家,望能够帮助大家提升!