Loadrunner11中webservice协议脚本总结
简介
    webservices协议是建立可交互操作的分布式应用程序的新平台,它通过一系列的标准和协议来保证程序之间的动态连接,其中最基本的协议包括soap,wsdl,uddi
    1)SOAP(simple object access protocl)
        SOAP是消息传递协议,它规定了web services之间如何传递消息。SOAP基于xml和xsd,xml是soap的数据编码方式,简单说soap规定了:

            a.传递信息的格式为xml,用于描述信息的内容和处理方法;
            b.远程对象方法调用的格式;
            c.异常处理以及其他的相关信息;
    2)WSDL(web services Description Language)
        WSDL是web services的定义语言,和soap一起构成web服务的核心结构单元。wsdl协议规定了有关webservices描述的标准
    3)UDDI(Universal Description,Discovery,and Intergration)
        UDDI是访问登记的标准,它建立了一个平台独立,开放的框架,通过英特网来描述服务,发现业务并整合业务服务。简单来说
        UDDI用于集中存放和查找wsdl描述文件,起着目录服务器的作用
 
脚本开发:
    简单介绍使用Loadrunner11来开发webservices协议的脚本三种方法,以天气预报接口为例
    1.当我们从开发那边知道接口的wsdl地址,可以使用 web_service_call()函数,具体操作如下:(http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl)
        1)打开LR,新建web service协议脚本(使用该协议,菜单栏就会出现SOA Tool选项)
            
        2) 选择菜单栏中SOA Tool---->Mangae Services,点击对话框中的import
                            
    3)在Import Service 对话框中的URL中输入wsdl地址,点击import,之后点击OK
        
    4)选择菜单栏中SOA Tool----> Add Service Call
            
    5)输入具体值之后点击OK按钮,等到如下脚本
            web_service_call( "StepName=getWeatherbyCityName_101", //步骤名称
                "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",//服务名称,soap,获取的接口
                "ResponseParam=response",//返回参数信息
                "Service=WeatherWebService", //webservice的服务
                "ExpectedResponse=SoapResult", //请求的返回
                "Snapshot=t1555551364.inf", //快照
                BEGIN_ARGUMENTS,  //开始输入
                "theCityName=南京",  //输入的参数值
                END_ARGUMENTS,    //结束输入
                BEGIN_RESULT,   //开始输出
                "getWeatherbyCityNameResult=Param_getWeatherbyCityNameResult",
                "getWeatherbyCityNameResult/*[2]=Param_cityname",//返回的城市
                END_RESULT,//结束输出      
                LAST);
      6)加入事务,参数化与if,对脚本进行判断(加了一个今日天气实况信息,发现该函数可以输出多个值
            lr_start_transaction("getWeatherbyCityName");
            web_service_call( "StepName=getWeatherbyCityName_101", //步骤名称
                "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",//服务名称,soap,获取的接口
                "ResponseParam=response",//返回参数信息
                "Service=WeatherWebService", //webservice的服务
                "ExpectedResponse=SoapResult", //请求的返回
                "Snapshot=t1555551364.inf", //快照
                BEGIN_ARGUMENTS,  //开始输入
                "theCityName={cityname}",  //输入的参数值
                END_ARGUMENTS,    //结束输入
                BEGIN_RESULT,   //开始输出
                "getWeatherbyCityNameResult=Param_getWeatherbyCityNameResult",
                "getWeatherbyCityNameResult/*[2]=Param_cityname",//返回的城市
                "getWeatherbyCityNameResult/*[11]=TodayWeather", //返回的对应城市信息
                END_RESULT,//结束输出      
                LAST);
 
      if(strcmp(lr_eval_string("{Param_cityname}"),lr_eval_string("{cityname}"))==0)
        {
            lr_end_transaction("getWeatherbyCityName", LR_PASS);
            lr_output_message("成功查询出%s的今日天气情况:%s",lr_eval_string("{Param_cityname}"),lr_eval_string("{TodayWeather}"));
        }
    else
        {
            lr_end_transaction("getWeatherbyCityName", LR_FAIL);    
            lr_output_message("返回的城市信息为:%s",lr_eval_string("{Param_string}"));
        }  
    7)脚本执行结果如下
        
 
2.当我们从开发那边知道接口的接口报文信息,可以使用soap_request()函数,接口文档地址为 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName
     以下是 SOAP 1.2 请求和响应示例
    1)先将请求xml保存为xml文件,如放置到F:\getWeatherbyCityName.xml
        
    2)点击菜单栏SOA Tool----> Add Import SOAP,在输入框中输入刚保存文件地址信息
        
 
 
 
 
 
 
 
3)点击Manage Services,输入url,SOAP Action 以及Response Parameter值,具体如下
        
    4)点击OK按钮等到的脚本如下
            soap_request("StepName=SOAP Request",                //步骤名称                        
                "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",    //url地址                                    
                "SOAPEnvelope=" //发送到服务器的XML
                "<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=t1555556002.inf",                                        
                LAST);
        5)加入事务,参数化与if,对脚本进行判断(注意输入参数为中文时,需要将NULL编码转换为utf-8,输出内容为乱码是需要将utf-8编码转换为NULL,使用lr_convert_string_encoding函数
            lr_convert_string_encoding(lr_eval_string("{cityname}"),NULL,"utf-8","city");
            lr_save_string(lr_eval_string("{city}"),"city_name");
            //添加事务
            lr_start_transaction("getcityname");
            soap_request("StepName=SOAP Request",                //步骤名称                        
                        "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",    //url地址                                    
                        "SOAPEnvelope=" //发送到服务器的XML
                        "<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>{city_name}</theCityName>"
                        "</getWeatherbyCityName>"
                        "</soap:Body>"
                         "</soap:Envelope>",                                        
                          "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName",                                        
                            "ResponseParam=response",    //存储服务器响应返回参数                                
                            "Snapshot=t1555556002.inf",                                        
                            LAST);
                //返回的信息乱码转译,并高亮打印
            lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg");
            lr_error_message(lr_eval_string("{msg}"));
           //返回值为xml文件格式,该函数自动将返回值转变为中文的了,不需要使用lr_convert_string_encoding,本例获取城市信息    
            lr_xml_get_values(
                  "XML={response}",//查看的xml
                 "Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]", //查看返回内容路径在,指定元素或者属性
                "ValueParam=getcityname", //存储返回的值
                LAST);
        //本例获取城市天气信息,与脚本判断无关,实际脚本中可以不需要,这边是强化记忆来着
        lr_xml_get_values(
                "XML={response}",//查看的xml
                "Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[11]", //查看返回内容路径在,指定元素或者属性
                "ValueParam=getWeatherby", //存储返回的值
                LAST);
            //断言判断
        if(strcmp(lr_eval_string("{getcityname}"),lr_eval_string("{cityname}"))==0)
                {
                lr_end_transaction("getcityname", LR_PASS);
                 lr_output_message("成功查询出%s的今日天气情况:%s",lr_eval_string("{cityname}"),lr_eval_string("{getWeatherby}"));
 
                    }
        else
                {
                        lr_end_transaction("getcityname", LR_FAIL);    
                        lr_output_message("查询失败,输入的城市与返回的城市信息不一致,输入城市信息为%s,返回城市信息为%s",lr_eval_string("{cityname}"),lr_eval_string("{getcityname}"));
                    }  
    6)脚本执行结果如下(实测无问题)
            
3.可以使用web_custom_request()函数,也可以做web service协议:
        1)将鼠标放置到需要插入脚本的地方,右击,选择增加步骤,输入 web_custom_request,弹出对应设置框
                
        2)点击OK得到的脚本如下
                web_custom_request("web_custom_request",
                "Method=POST",
                "TargetFrame=",
                "Resource=0",
                "Referer=",
                "Mode=HTTP",
                "EncType=text/xml; charset=utf-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>
                     <getWeatherbyCityName xmlns="http://WebXml.com.cn/">
                     <theCityName>string</theCityName>
                     </getWeatherbyCityName>
                     </soap:Body>
                     </soap:Envelope>",
                    LAST);
        3)需要将body中的“”进行转译,且Body都需要加上引号,优化之后如下
                web_custom_request("web_custom_request",
                    "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",
                    "Method=POST",
                    "TargetFrame=",
                    "Resource=0",
                    "Referer=",
                     "Mode=HTTP",
                      "EncType=text/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>string</theCityName>"
                      "</getWeatherbyCityName>"
                     "</soap12:Body>"
                     "</soap12:Envelope>",
                LAST);
         4)加入事务,加关联,if,对脚本进行判断(注意使用lr_convert_string_encoding函数转码)
                lr_convert_string_encoding(lr_eval_string("{cityname}"),NULL,"utf-8","city");
                lr_save_string(lr_eval_string("{city}"),"city_name");
                web_reg_save_param_ex(
                    "ParamName=weather_city",
                     "LB=<string>",
                   "RB=</string>",
                    "Ordinal=2",
                SEARCH_FILTERS,
                LAST);
 
            lr_convert_string_encoding(lr_eval_string("{weather_city}"),NULL,"utf-8","weather_city1");
            lr_error_message(lr_eval_string("{weather_city1}"));
            lr_start_transaction("weather");
            web_custom_request("web_custom_request",
                    "Method=POST",
                "TargetFrame=",
                "Resource=0",
                "Referer=",
                "Mode=HTTP",
                "EncType=text/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>{city_name}</theCityName>"
                      "</getWeatherbyCityName>"
                     "</soap12:Body>"
                     "</soap12:Envelope>",
                LAST);
 
         if(strcmp(lr_eval_string("{weather_city1}"),lr_eval_string("{cityname}"))==0)
                {
                        lr_end_transaction("weather", LR_PASS);
                }
        else
                {
                    lr_end_transaction("weather", LR_FAIL);    
                    }  
 
SOAP工具的简单实用
    当我们只知道wsdl地址时,我们可以使用该工具知道具体的请求体,具体如下
        1)打开工具,点击页面上的SOAP
                
        2)点击ok,成功项目,点击其他具体的接口,可查看到请求体信息,输入参数,即可得到返回信息(左边请求信息,右边返回信息)
                

Loadrunner11中webservice协议脚本总结的更多相关文章

  1. 性能测试总结工作总结-基于WebService协议脚本 内置函数手动编写

    LoadRunner基于WebService协议脚本 WebService协议脚本有三种生成方式,一种是直接通过LoadRunner导入URL自动解析生成:一种是使用LoadRunner内置函数手动编 ...

  2. LR11中webservice协议的性能测试应用

    使用LR11对webservice协议的接口测试应用 脚本开发步骤:1.打开vuser generator,新建一个脚本,选择webservice协议:2.选择Manage Services(服务管理 ...

  3. LR编写webservice协议接口

    转自:http://lovesoo.org/use-loadrunner-call-webservice-interface-testing-optimization-summary.html 本文主 ...

  4. webservice中采用协议Http,它是指什么意思

    webservice 协议 Web Service使用的是 SOAP (Simple Object Access Protocol)协议soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有 ...

  5. LoadRunner系列之—-02 基于webservice协议的接口测试(脚本实例)

    Loadrunner 基于webservice协议的接口压力测试(脚本实例) 接口功能如下:请求接口,报文只有一个参数为证件号码:返回报文中,有证件号码是否能查到对应数据,查到几条数据. 思路:请求w ...

  6. Loadrunner测试webservice协议总结

    Loadrunner测试webservice协议总结 一.协议选择 1.打开Virtual user generator,新建脚本,选择webservice协议

  7. Loadrunner11点击录制脚本无响应,IE页面弹不出——解决方案汇总

    以前用Loadrunner的时候都没有遇到过这个问题,后来将服务器重装系统(win7)后,重新安装Loadrunner11,浏览器版本刚开始为IE11,后来降为IE8,IE访问部署在虚拟机里的平台能正 ...

  8. lr_java user协议脚本开发

    1.准备工作,安装jdk,配置环境变量 lr11 jdk1.6 32位 lr12 jdk1.7 32位 注:若原已安装了jdk1.8,现要安装jdk1.7,若遇到安装好1.7并配置好环境后,在cmd中 ...

  9. [WebService].net中WebService的使用实例

    .net中WebService的使用实例 一.创建一个Webwebservice 1.新建一个项目WebserverDemo 2.在项目处添加新建项,添加一个web服务 3.编辑TestServer. ...

随机推荐

  1. 浅谈USB驱动架构 转载

    去年,老师让我分析基于HD3系统芯片的WindowsCE USB驱动的可行性.USB驱动非常庞大,多个软件层次相互交错,以及各种协议,USB系统对于一般人很难理解,我对其也只是理解一个大概,下面,我对 ...

  2. Ubuntu下载

    由于官网服务器在国外,下载速度奇慢,所以我们可以利用阿里云镜像下载ubuntuubuntu 14.04:http://mirrors.aliyun.com/ubuntu-releases/14.04/ ...

  3. vue实现验证码倒计时60秒的具体代码

    vue实现验证码倒计时60秒的具体代码 <span v-show="show" @click="getCode">获取验证码</span> ...

  4. Character

    Character a = new Character(); Character.isUpperCase(a) 判断给点的字符是否是大写字符 Character.isLowerCase(a) 判断给定 ...

  5. Docker初始

    如今Docker的使用已经非常普遍,特别在一线互联网公司.使用Docker技术可以帮助企业快速水平扩展服务,从而到达弹性部署业务的能力.在云服务概念兴起之后,Docker的使用场景和范围进一步发展,如 ...

  6. Web 前端编程运维必备

    Html 1.Html 标签初知 2.Html 标签种类 3.Html 符号 4.Html Title 标签 5.Html meta 标签 6.Html Link 标签 7.Html p 标签 8.H ...

  7. JS制作蔡徐坤打篮球小游戏(鸡你太美?)

    一.前提: 和我之前写的 QT小球游戏 差不多(指的是实现方法). 感谢大佬的 Github:https://github.com/kasuganosoras/cxk-ball 外加游戏网页:http ...

  8. linux系统ansible一键完成三大服务器基础配置(剧本)

    ansible自动化管理剧本方式一键完成三大服务器基础配置 环境准备:五台服务器:管理机m01:172.16.1.61,两台web服务器172.16.1.7,172.16.1.8,nfs存储服务器17 ...

  9. Android中碎片的添加问题

    碎片在Android中的应用是十分广泛的,它就像是嵌在活动中的另一个活动就像是一个容器包含了另一个容器,那么到底该怎么添加碎片呢?主要有两种方法,一种是在该碎片所在的xml文档中使用Android:n ...

  10. spring boot+自定义 AOP 实现全局校验

    最近公司重构项目,重构为最热的微服务框架 spring boot, 重构的时候遇到几个可以统一处理的问题,也是项目中经常遇到,列如:统一校验参数,统一捕获异常... 仅凭代码 去控制参数的校验,有时候 ...