博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lr11之web services协议脚本开发
阅读量:6326 次
发布时间:2019-06-22

本文共 7068 字,大约阅读时间需要 23 分钟。

 

一:Web services协议介绍

Web services协议是建立可交互操作的分布式应用程式的新平台,通过一系列标准和协议来保证程序之间的动态链接,其中最基本的协议包括三种:SOAP、WSDL、UDDI。SOAP是基于xml和xsd,xml是soap的编码方式;WSDL是web services的定义语言,和soap一起构成了web服务的核心结构单元;UDDI用于集中存放和查找wsdl描述文件,起着目录服务器的作用。

二:Web services协议的模式开发

Webservice协议分为3个模式开发Web services脚本:web_Service_call、soap_request、web_custom_request.

 

三、web_Service_call模式开发Web services脚本步骤如下:

步骤一:新建脚本,选择web services协议

 

 

步骤二:将鼠标移动到action里面,点击manage services

 

 

步骤三:点击import

  

 

步骤四:选择url,输入地址,点击import

 

 

Ps:如需要登录,则可点击connection setting按钮进行登录设置,否则其他信息可不用填写

 

步骤五:自己点击ok,其他信息可不用管.

 

 

步骤六:点击add service

 

 

步骤七:在select web service call处选择要测试的服务器名称,勾选图中”1”标识的复选框,将返回结果保存到图中”2”标识的param_string参数中,然后点击ok

 

 

步骤八:保存后出现如下脚本

Action()

{

 

         web_service_call( "StepName=getWeatherbyCityName_102",

                   "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",

                   "ResponseParam=response",

                   "Service=WeatherWebService",

                   "ExpectedResponse=SoapResult",

                   "Snapshot=t1555574612.inf",

                   BEGIN_ARGUMENTS,

                   END_ARGUMENTS,

                   BEGIN_RESULT,

                   "getWeatherbyCityNameResult/*[1]=Param_string",

                   END_RESULT,

                   LAST);

 

 

         return 0;

}

 

步骤九:加强脚本,对脚本添加事务、参数化、断言

Action()

{

    //添加事务

   

         lr_start_transaction("获取城市天气预报");

 

         web_service_call(

                   "StepName=getWeatherbyCityName_101",//函数名称

                   "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",//用soap协议获取城市天气预报

                   "ResponseParam=response",//返回参数信息

                   "Service=WeatherWebService",//服务名

                   "ExpectedResponse=SoapResult",//返回结果

                   "Snapshot=t1555556612.inf",//快照

                   BEGIN_ARGUMENTS,   //输入参数开始

                   "theCityName={cityname}",//输入的参数值,{cityname}是参数化

                   END_ARGUMENTS,    //输入参数结束

                   BEGIN_RESULT,    //返回结果开始

                   "getWeatherbyCityNameResult/*[2]=Param_string",//返回结果保存到Param_string值中

                   END_RESULT,    //返回结果结束

                   LAST);

         //根据输入的cityname值对比返回结果值Param_string,来做if判断事务是否成功,若字符串相等则事务成功,反正则失败

        if (strcmp(lr_eval_string("{cityname}"),lr_eval_string("{Param_string}")) ==0)

                            {

           

               lr_end_transaction("获取城市天气预报", LR_PASS);

 

                   }

                   else

                   {

           lr_end_transaction("获取城市天气预报", LR_FAIL);

                   }

 

         return 0;

}

步骤十:运行脚本,响应结果如下:

 

 

从上图中很明显可看到事务通过了。

 

四、soap_request模式开发Web services脚本步骤如下:

 

步骤一:打开测试地址

步骤二:将下图红色截图中信息复制到记事本中,并将文档保存为.xml格式的文件

 

步骤三:新建脚本,选择web services协议

 

 

步骤四:点击import soap

 

步骤五:选择步骤二中保存的文件,点击load

 

步骤六:输入url、soap action、response parameter(返回消息参数名称),点击ok

(ps:步骤一url打开后可查看到接口的请求url和soap action值)

 

 

步骤七:保存后脚本如下

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>string</theCityName>"

                                     "</getWeatherbyCityName>"

                            "</soap:Body>"

                   "</soap:Envelope>",                                                                                           

                   "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName",                                                                                     

                   "ResponseParam=response",                                                                                             

                   "Snapshot=t1555575536.inf",                                                                                       

                   LAST);

 

         return 0;

}

 

步骤八:在脚本中加入编码格式

 

 

步骤九:soap请求中用lr_xml_get_values函数获取返回的xml

 

 

步骤十:最后加强脚本,添加事务、参数化、断言,最后脚本如下:

注意:参数化中如为中文时,要先转码,否则运行脚本会报错,出现乱码

Action()

{

   

         lr_start_transaction("获取城市天气预报");

 

    lr_convert_string_encoding(lr_eval_string("{citynamevalue}"),NULL,"utf-8","str");//城市名称参数进行参数化,并将参数中的中文先转码,保存到str,

    lr_save_string(lr_eval_string("{str}"),"strmsg");//将获取到的str值保存到strmsg值中

         soap_request(

                   "StepName=SOAP Request",           //步骤名称                                                                      

                   "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",                       //url地址                                                                

                   "SOAPEnvelope="//发送到服务器的xml包格式

        "<?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>"           //请求的body

                                     "<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"

                                               "<theCityName>{strmsg}</theCityName>"   //请求的参数,中文要转码

                                     "</getWeatherbyCityName>"

                            "</soap:Body>"

                   "</soap:Envelope>",                                                                                           

                   "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName",                                                                                     

                   "ResponseParam=response",                                      //返回的信息保存到response,这个已经可以打印了,不用单独加打印信息                                                  

                   "Snapshot=t1555560503.inf",                   //快照                                                                 

                   LAST);

       lr_convert_string_encoding(lr_eval_string("{response}"),"UTF-8",NULL,"msg");//将response转换为中文

       //获取返回的xml

            lr_xml_get_values(

                      "XML={response}",//获取返回的消息体,从response值中查找xml格式的消息体

                      "Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]",//对返回的xml进行制定路径后元素的查找

                           "ValueParam=cityname",//查找结果存储的参数名

                           LAST);

            lr_error_message("返回的城市名称:%s",lr_eval_string("{cityname}"));

       if(strcmp(lr_eval_string("{cityname}"),lr_eval_string("{citynamevalue}"))==0)//这点一定要注意下,要用未转码的参数值与获取到的xml值进行对比,如果用转码后的参数值与获取到的xml值对比,则字符串不一致,会失败

                        {

           

               lr_end_transaction("获取城市天气预报", LR_PASS);

 

                   }

                   else

                   {

           lr_end_transaction("获取城市天气预报", LR_FAIL);

                   }

 

         return 0;

}

 

步骤十一:运行脚本,响应结果如下:

 

 

从上图中很明显可看到事务通过了。

 

 

五、web_custom_request模式开发Web services脚本步骤如下:

步骤一:新建脚本,选择web services协议

 

 

步骤二:鼠标移动到action里面,右击-insert-new-step

 

步骤三:选择custom request ,点击ok

 

步骤四:输入Method方法(一定要大写),输入url、body请求体,勾选record mode为 HTTP,勾选Encoding Type并输入编码方式,然后点击确定按钮

(ps:所有信息在给的接口文档中都可找到)

 

 

步骤五:保存后脚本如下:

Action()

{

 

         web_custom_request("web_custom_request",

                   "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",

                   "Method=POST",

                   "TargetFrame=",

                   "Resource=0",

                   "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>string</theCityName>

                                     </getWeatherbyCityName>

                              </soap12:Body>

                            </soap12:Envelope>",

                   LAST);

 

        

         return 0;

}

 

步骤六:将body里面的请求体,全部加上双引号”,并将原本存在的双引号用”\”进行转义,脚本如下:

 

步骤七:加强脚本,在脚本里面加入事务、参数、断言,最后脚本如下:

Ps:用web_reg_save_param_ex函数获取返回值,并用获取的值用strcmp函数进行字符串对比

Action()

{

    lr_start_transaction("获取城市天气预报");

 

    lr_convert_string_encoding(lr_eval_string("{citynamevalue}"),NULL,"utf-8","str");//城市名称参数进行参数化,并将参数中的中文先转码,保存到str,

    lr_save_string(lr_eval_string("{str}"),"strmsg");//将获取到的str值保存到strmsg值中

 

    //获取xml个中第二个string值

         web_reg_save_param_ex(

                   "ParamName=string",

                   "LB=<string>",//左边界

                   "RB=</string>", //右边界

                   "Ordinal=2",//获取第一个值

                   SEARCH_FILTERS,

                   "Scope=ALL",

                   LAST);

 

 

         web_custom_request("web_custom_request",

                   "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",//url地址

                   "Method=POST",    //post请求

                   "TargetFrame=",

                   "Resource=0",

                   "Referer=",

                   "Mode=HTTP",

                   "EncType= application/soap+xml; charset=utf-8",//编码方式

                   "Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"  //注意:body下都要加双引号"",且如果本身里面有"",则要转义

                                     "<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>{strmsg}</theCityName>"

                                               "</getWeatherbyCityName>"

                                       "</soap12:Body>"

                                     "</soap12:Envelope>",

                   LAST);

 

        

         lr_convert_string_encoding(lr_eval_string("{string}"),"UTF-8",NULL,"msg");//将获取到string值转换为中文

         if(strcmp(lr_eval_string("{msg}"),lr_eval_string("{citynamevalue}"))==0)//这点一定要注意下,要用未转码的参数值与获取到的string值进行对比

                    {

 

            lr_end_transaction("获取城市天气预报", LR_PASS);

 

          }

          else

          {

                   lr_end_transaction("获取城市天气预报", LR_FAIL);

          }

   

         return 0;

}

 

步骤八:运行脚本,响应如下:

 

从上图中很明显可看到事务通过了。

 

转载于:https://www.cnblogs.com/feiyang450blogs/p/10730836.html

你可能感兴趣的文章
java关于split分割字符串,空的字符串不能得到的问题
查看>>
JavaScript函数式编程
查看>>
C++_系列自学课程_第_6_课_bitset集_《C++ Primer 第四版》
查看>>
java对象数组
查看>>
Android中使用dimen定义尺寸(转)
查看>>
Webserver管理系列:11、注意默认的隐含共享
查看>>
《学习OpenCv》 笔记(1)
查看>>
[百度]数组A中任意两个相邻元素大小相差1,在其中查找某个数
查看>>
温故而知新:Delegate,Action,Func,匿名方法,匿名委托,事件
查看>>
strtok、strtok_s、strtok_r 字符串切割函数
查看>>
shell编程基础(5)---循环指令
查看>>
八皇后问题
查看>>
.NET破解之爱奇迪(二)
查看>>
C#反射方法学习
查看>>
MD5加密解密
查看>>
.Net 转战 Android 4.4 日常笔记(6)--Android Studio DDMS用法
查看>>
SVN被锁定的几种解决方法
查看>>
js如何判断是否在iframe中及防止网页被别站用 iframe嵌套 (Load denied by X-Frame-Options)...
查看>>
ios ios7 取消控制拉升
查看>>
182在屏幕中实现网格化视图效果
查看>>