性能测试学习 第八课--LR12中针对WebServices协议的三种脚本开发模式
一,webservices协议简介
webservices是建立可交互操作的分布式应用程序的新平台,它通过一系列的标准和协议来保证程序之间的动态连接,
其中最基本的协议包括soap,wsdl,uddi.
1,SOAP(simple object access protocl)
SOAP是消息传递协议,它规定了web services之间如何传递消息。SOAP基于xml和xsd,xml是soap的数据编码方式。
2,WSDL(web services Description Language)
WSDL是web services的定义语言,和soap一起构成web服务的核心结构单元。wsdl协议规定了有关webservices描述的标准。
3,UDDI(Universal Description,Discovery,and Intergration)
UDDI是访问登记的标准,它建立了一个平台独立,开放的框架,通过英特网来描述服务,发现业务并整合业务服务。简单来说
UDDI用于集中存放和查找wsdl描述文件,起着目录服务器的作用。
二,我们在性能测试的工作中,难免会遇到webservices协议的接口,这里我简单介绍一下用loadrunner12来开发webservices协议脚本
的三种模式,咱们就以天气预报的网站来为例吧:
1,web_service_call模式
1)启动“virtual user Generator”,新建“web services”虚拟用户,

2)选择上方SOA Tool中的Add Service Call,如下图

3)弹出New Web Service Call对话框,选择Service-import service

4)输入要测试的网址

5)下面选择Operation,输入城市,以及设置获取返回值参数



6)点击OK后,得到下面的脚本
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Action(){ web_service_call( "StepName=getWeatherbyCityName_104", //步骤名称 "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName", //服务名称|soap获取哪个接口 "ResponseParam=response", //返回的参数信息 "Service=WeatherWebService", //webservices的服务 "ExpectedResponse=SoapResult", //请求返回的信息 "Snapshot=t1555545923.inf", //快照 BEGIN_ARGUMENTS, //输入参数开始 "theCityName=广州", //请求的参数与值 END_ARGUMENTS, //结束参数 BEGIN_RESULT, //返回值的开始 "getWeatherbyCityNameResult/*[1]=Param_string", //保存返回参数 END_RESULT, //返回值结束 LAST); return 0;} |
6)然后做参数化,断言
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
Action(){ lr_start_transaction("获取天气预报"); web_service_call( "StepName=getWeatherbyCityName_104", //步骤名称 "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName", //服务名称|soap获取哪个接口 "ResponseParam=response", //返回的参数信息 "Service=WeatherWebService", //webservices的服务 "ExpectedResponse=SoapResult", //请求返回的信息 "Snapshot=t1555545923.inf", //快照 BEGIN_ARGUMENTS, //输入参数开始 "theCityName={city_name}", //请求的参数与值 END_ARGUMENTS, //结束参数 BEGIN_RESULT, //返回值的开始 "getWeatherbyCityNameResult/*[2]=Param_string", //保存返回参数 END_RESULT, //返回值结束 LAST); if(strcmp(lr_eval_string("{Param_string}"),lr_eval_string("{city_name}"))==0) { lr_end_transaction("获取天气预报",LR_PASS); } else { lr_end_transaction("获取天气预报",LR_FAIL); } return 0;} |
7)最后保存,设置日志级别,然后Replay我们的脚本

2,soap_request模式
1)打开WeatherWebService网站,

2)复制上面的代码,在notepad++中新建一个文件,将代码粘贴上去,保存到D盘,然后在loadrunner12中
点击下图的import SOAP


3)在对话框中,我们输入保存的xml文件地址,输入URL,URL=http://{Host}+{POST} 参数从
上图所示取,输入对应的SOAPAction,具体如下图所示

4)点击OK,生成下面的脚本
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
Action(){ soap_request("StepName=SOAP Request", "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.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>" "<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">" "<theCityName>广州</theCityName>" "</getWeatherbyCityName>" "</soap:Body>" "</soap:Envelope>", "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName", "ResponseParam=response", "Snapshot=t1555549382.inf", LAST); return 0;} |
5)这里有个难题就是如何做xml断言?我们看一下下图的响应示例
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: length<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <getWeatherbyCityNameResponse xmlns="http://WebXml.com.cn/"> <getWeatherbyCityNameResult> <string>string</string> <string>string</string> </getWeatherbyCityNameResult> </getWeatherbyCityNameResponse> </soap12:Body></soap12:Envelope> |
这里引入lr_xml_get_values函数来获取xml的返回值

XPath query中填入city值的xpath定位的绝对路径:/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]
6)最后加入事物函数,做断言
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
Action(){ lr_convert_string_encoding(lr_eval_string("{city_name}"),NULL,"utf-8","city"); lr_save_string(lr_eval_string("{city}"),"cityName"); lr_start_transaction("获取天气预报"); soap_request("StepName=SOAP Request", "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.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>" "<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">" "<theCityName>{cityName}</theCityName>" "</getWeatherbyCityName>" "</soap:Body>" "</soap:Envelope>", "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName", "ResponseParam=response", "Snapshot=t1555549382.inf", LAST); lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg"); lr_xml_get_values( "XML={response}", "Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]", "ValueParam=city_code", LAST); lr_output_message("返回城市名称:%s",lr_eval_string("city_code")); if(strcmp(lr_eval_string("{city_code}"),lr_eval_string("{city_name}"))==0) { lr_end_transaction("获取天气预报", LR_PASS); } else { lr_end_transaction("获取天气预报", LR_FAIL); } return 0;} |
7)保存后点击Replay,得到下面的结果:

3,web_custom_request模式

输入对应的URL,body里面输入SOAP的请求体,点击确定,最后生成如下的代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
Action(){ web_custom_request("web_services", "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx", "Method=POST", "TargetFrame=", "Resource=1", "Referer=", "Mode=HTTP", "EncType=application/soap+xml; charset=utf-8", "Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>""<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" "<soap12:Body>" "<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">" "<theCityName>59287</theCityName>" "</getWeatherbyCityName>" "</soap12:Body>""</soap12:Envelope>", LAST); return 0;} |
后面做脚本强化就行了。
性能测试学习 第八课--LR12中针对WebServices协议的三种脚本开发模式的更多相关文章
- LR12中针对WebServices协议的三种脚本开发模式
一,webservices协议简介 webservices是建立可交互操作的分布式应用程序的新平台,它通过一系列的标准和协议来保证程序之间的动态连接, 其中最基本的协议包括soap,wsdl,uddi ...
- 性能测试学习 第七课 --loadrunner中JavaVuser脚本的编写
1.环境准备: LoadRunner11----->对应JDK1.6版本(32位) LoadRunner12----->对应JDK1.7版本(32位) (一).JDK下载安装完成 ...
- 六十八、SAP中内表插入的三种方法之二,COLLECT的使用,用于计算数字字段之和
一.使用COLLECT时,如果关键字没有,那么插入,如果有则求所有关键字列的和,代码如下 二.sy-index在循环中,每次循环从1开始递增 三.查看T_DATA数据 四.如下 五.循环时候,我们查看 ...
- vue中通过cross-env插件配置三种环境(开发,测试,生产)打包,不用切换api
1. 话不多说,第一步就是安装必要的插件 npm install cross-env --save 2.修改config里面的参数,这里只展示一个test,其他类似 3.修改package.json ...
- python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍
目录 python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍.md 一丶字典 1.字典的定义 2.字典的使用. 3.字典的常用方法. python学习第八讲,python ...
- Elasticsearch7.X 入门学习第八课笔记-----索引模板和动态模板
原文:Elasticsearch7.X 入门学习第八课笔记-----索引模板和动态模板 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接: ...
- Java中获取键盘输入值的三种方法
Java中获取键盘输入值的三种方法 Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值 ...
- Tomcat中部署web应用的三种方式
Tomcat中部署web应用的三种方式(静态部署) 第一种,针对war或解压后的war,最为常用的是直接操作webapp目录,将完整的war包或者web应用直接放到webapp目录下.使用 ...
- MVC3中,在control里面三种Html代码输出形式
MVC3中,在control里面三种Html代码输出形式:ViewData["msg"] = "<br /> Title <br />" ...
随机推荐
- string format的各类格式及用法
数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4} $12.3656 货币 "¥{0:N2}" ¥12.36 ...
- Java 基本语法,标识符,修饰符,关键字
基本语法 编写 Java 程序时,应注意以下几点: 大小写敏感:Java 是大小写敏感的,这就意味着标识符 Hello 与 hello 是不同的. 类名:对于所有的类来说,类名的首字母应该大写.如果类 ...
- 实践笔记_J2EE_Server_Tomcat_tomcat域名绑定_1_单域名绑定
Tomcat域名绑定(1)单域名绑定 1. 测试环境说明 名称 版本 ...
- Python中的命名空间概念
python使用命名空间记录变量.python中的命名空间就像是一个dict,key是变量的名字,value是变量的值. python中,每个函数都有一个自己的命名空间,叫做local namespa ...
- 2018年最新JAVA面试题总结之数据库(3)
转自于:https://zhuanlan.zhihu.com/p/39804394 1.MySQL的delete与truncate区别? 回答:delete语句执行删除的过程是每次从表中删除一行,并且 ...
- 末学者笔记--SSHD服务及SCP用法
sshd服务讲解 1.SSHD服务 介绍:SSH 协议:安全外壳协议.为 Secure Shell 的缩写.SSH 为建立在应用层和传输层基础上的安全协议. 默认端口22 作用: sshd服务使用SS ...
- Angular Material design设计
官网: https://material.io/design/ https://meterial.io/components 优秀的Meterial design站点: http://material ...
- oracle数据库学习
trunc(number[,decimals])--number 待做截取处理的数值:decimals 指明需保留小数点后面的位数 CREATE PUBLIC DATABASE LINK Co ...
- 小程序-组件component和模版template的选择和使用
小程序提供了组件component和模版template那什么时候 选择哪一个使用呢?我总结了一下 template主要是模版,对于重复的展示型模块进行展示,其中调用的方法或者数据data都是需要引用 ...
- webserver开发
https://www.cnblogs.com/zakun/p/5387910.html