LR11的webservice脚本的三种使用方式

今天简单给需要用的朋友们介绍下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不同方式实现脚本已提供给大家,望能够帮助大家提升!

Loadrunner工具概述 4 工具简介 4 下载 4 安装 5 在windows下安装loadrunner 5 在liunx下安装Load Generator组件 6 LoadRunner主要组件 7 工作原理 7 LR自带实例 8 负载流程 9 Loadrunner引导界面 9 VuGen--组件概述 10 VuGen--脚本创建 10 脚步创建流程 10 VuGen起始页 11 协议支持选择 11 协议种类 12 协议选择方法 14 协议选择注意要点 16 开始录制(Start Recording)及选项(Recording Option) 16 Internet 应用程序录制选项 20 Win32应用程序录制选项 21 常规选项—脚本(General--Script) 21 常规选项—协议(General—Protocols) 22 常规选项—录制(General—Recording) 22 网络—端口映射(NetWork—Port Mapping) 28 HTTP属性—高级(HTTP Properties--Advanced) 29 HTTP属性—关联(HTTP Properties--Correlation) 31 VuGen--脚本录制 32 录制步骤 32 脚本查看 33 脚本Action介绍 34 VuGen--脚本回放 35 Web(HTTP/HTML)常规选项 35 参数化(Parameterization) 35 回放(Replay) 35 环境(Environment) 36 显示(Display) 37 关联(Correlation) 37 Web(HTTP/HTML)运行设置 37 运行逻辑(Run Logic) 38 步(Pacing) 39 日志(Log) 39 思考时间(Think Time) 40 其他(Miscellances) 41 VuGen--增强功能 42 事务 42 参数化 43 内容检查 49 关联 50 集合点 53 Controller组件概述 55 设计场景思想 55 新建场景方式 56 场景类型 56 场景运行 59 执行步骤 60 场景运行期间增加负载 61 系统监控 62 监控负载下的客户端程序 62 实时观察Vuser运行情况 62 Load Generator组件概述 64 Generator连接 64 IP虚拟 64 添加IP地址 65 使用虚拟IP 65 IP虚拟使用误区 66 Analysis组件概述 66 服务水平协议 68 定义SLA 69 常用性能指标介绍 71 事务(Transation) 71 Web资源分析(Web Resources) 72 网页元素细分(Web Page Breakdown) 74 其他指标 76 性能测试资源占用率分析方法 76 附录:LoadRunner常用函数 77
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值