一,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后,得到下面的脚本

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)然后做参数化,断言

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,生成下面的脚本

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断言?我们看一下下图的响应示例

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-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)最后加入事物函数,做断言

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的请求体,点击确定,最后生成如下的代码

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协议的三种脚本开发模式的更多相关文章

  1. 性能测试学习 第八课--LR12中针对WebServices协议的三种脚本开发模式

    一,webservices协议简介 webservices是建立可交互操作的分布式应用程序的新平台,它通过一系列的标准和协议来保证程序之间的动态连接, 其中最基本的协议包括soap,wsdl,uddi ...

  2. vue中通过cross-env插件配置三种环境(开发,测试,生产)打包,不用切换api

    1. 话不多说,第一步就是安装必要的插件 npm install cross-env --save 2.修改config里面的参数,这里只展示一个test,其他类似 3.修改package.json ...

  3. Java中获取键盘输入值的三种方法

    Java中获取键盘输入值的三种方法     Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值 ...

  4. 【Loadrunner】使用LR录制HTTPS协议的三种方法

    使用LR录制HTTPS协议的三种方法 一.最简单的方法:浏览器配置打开浏览器,安装证书,配置完成后直接用http协议录制即可(配置完成的标识就是打开网页,不显示安全提示) 二.LR配置修改操作步骤如下 ...

  5. 【转载】取得系统中网卡MAC地址的三种方法

    From:http://blog.csdn.net/zhangting1987/article/details/2732135 网卡地址这个概念有点混淆不清.因为实际上有两个地址,mac地址和物理地址 ...

  6. Tomcat中部署web应用的三种方式

    Tomcat中部署web应用的三种方式(静态部署)       第一种,针对war或解压后的war,最为常用的是直接操作webapp目录,将完整的war包或者web应用直接放到webapp目录下.使用 ...

  7. 【mvrp多协议vlan注册协议给予三种注册方式的验证】

    MVRP 多vlan注册协议给予三种注册模式的配置 一:根据项目需求搭建好拓扑图如下 二:配置: 首先对项目做理论分析,sw1,sw2,sw3所组成的直连网络中,为使不同的PC之间进行通信,按vlan ...

  8. MVC3中,在control里面三种Html代码输出形式

    MVC3中,在control里面三种Html代码输出形式:ViewData["msg"] = "<br /> Title <br />" ...

  9. Android平台中实现对XML的三种解析方式

    本文介绍在Android平台中实现对XML的三种解析方式. XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为Android开发中一项重要的技能. 在 ...

随机推荐

  1. MongDB增删改查

    增加 增加一条:db.th.insertOne({}) // 返回 _id 增加多条:db.th.insertMany([{},{},{}]) // 返回 _ids 针对Array增加操作: db.s ...

  2. HTML入门5

    格式化文本,高阶处理,接下来了解,标记引文,描述列表,计算机代码和其他文本,上下标,联系信息等数据. 学习不太知名的HTML元素来标记高级语义特征. 描述列表,也叫自定义列表,第三种类型的列表,除了u ...

  3. bootstrap_响应式布局简介_媒体查询_媒体选择器_2x3x图

    响应式布局 在不同设备上,同一网页根据设备特性(显示屏大小,分辨率)呈现不同的布局样式. 思考: 获取设备相关信息 将屏幕划分为几个区域 给需要变化的结构写多套 css 样式 媒体查询 常用写法 @m ...

  4. Lecture3.随机变量及其概率分布

    1.随机变量的定义 2.随机变量的类型: 若随机变量X的可能取值是有限个或可列个, 则称X为离散型随机变量. 反之,则称X为非离散型随机变量. 若随机变量X的可能取值“连续”(“不间断”),则称X 为 ...

  5. SQL之NULL值的几种处理方式

    1.创建测试表: drop table if exists tab_null_operator; create table tab_null_operator as select 1 as id,'c ...

  6. Vue.js中使用select选择下拉框

    在Vue.js中使用select选择下拉框有两种方法: 第一种: Add.html: <select v-model="sysNotice.noticeType" id=&q ...

  7. Python3学习之路~7.3 反射

    python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,该四个函数分别用于对对象内部执行:检查是否含有某成员.获取成员.设置成员.删除成员. ...

  8. js比较两个单独的数组或对象是否相等

    所谓js的中的传值,其实也就是说5种基本数据类型(null,undefind,boolean,number,string) 传引用也就是说的那个引用数据类型,(array和object) 基本数据类型 ...

  9. html5+css基础

    最近在学习html+css3基础教程,整理了一些基础知识点.在此与大家分享. 1.盒模型 定义:css处理网页时,它认为每个元素都包含在一个不可见的盒子里,即我们所熟知的盒模型.其中它的主要属性有:h ...

  10. [LeetCode] 120. Triangle _Medium tag: Dynamic Programming

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...