• LR12中针对WebServices协议的三种脚本开发模式


    Loadrunner 脚本开发实战-webservice 协议

     第一种: 

    使用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

    点击ok,生成函数:

    web_service_call( 
            "StepName=getWeatherbyCityName_101",  //步骤的名称
            "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",  //服务名称 soap 获取哪个接口(城市天气预报)
            "ResponseParam=response",      //返回的参数信息
            "Service=WeatherWebService",     //webservice 的服务
            "ExpectedResponse=SoapResult",     //请求的返回
            "Snapshot=t1555665434.inf",        //快照
            BEGIN_ARGUMENTS,              //开始输入参数
            "theCityName={city_name}",          //请求输入 城市=。。。
            END_ARGUMENTS,       //结束参数
            BEGIN_RESULT,//返回值的开始
            "getWeatherbyCityNameResult/*[2]=Param_string",  //返回参数保存在Param_string中
            END_RESULT, // 返回值的结束
            LAST);

    开启扩展日志,去运行脚本

    脚本乱码,去复制到文本中设置编码后查看

    第二种:

    http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName

    lr_xml_get_values()函数的使用

    运行报:

    鐨勮�姹x82

    Action.c(7): Error:HTTP status code 400 returned by the server

    Action.c(7): Error:SOAP request "SOAP Request" execu

    需要重建项目,去运行

    参考脚本:

    Action()
        
    {
        //lr_convert_string_encoding("{cityname}",NULL,"utf-8","cityname");  // 对中文UTF-8转换成lr的编码方式
        lr_convert_string_encoding(lr_eval_string("{cityname}"),NULL,"utf-8","cityname");
        lr_save_string(lr_eval_string("{cityname}"),"city_name");//字符串1的值赋值给字符串2
        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>"
                    "<getWeatherbyCityName xmlns="http://WebXml.com.cn/">"
                        "<theCityName>{cityname}</theCityName>"
                    "</getWeatherbyCityName>"
                "</soap:Body>"
            "</soap:Envelope>",                                        
            "SOAPAction=http://WebXml.com.cn/getWeatherbyCityName",                                        
            "ResponseParam=response",            //存贮服务器响应的输出参数的名称                            
            "Snapshot=t1555667792.inf",            //快照                            
            LAST);
        
        lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg");  // 对中文进行UTF-8转码
        
        //根据xml信息去填入
        lr_xml_get_values("XML={response}",   //获取返回消息体
                          "Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]",//对输入的,返回的字符串xml 的查找或快速查找,可指定元素或者属性
                          "ValueParam=responseValue",            //存贮查询结果的输入参数的名称 自己取的名称
                          LAST);              // yes 会出来匹配的所有元素 no 只匹配一个
        
        
        lr_output_message("返回城市名称:%s",lr_eval_string("{responseValue}"));
        if(strcmp(lr_eval_string("{responseValue}"),lr_eval_string("{cityname}"))==0){ //响应的参数  与参数化转码之前的参数对比
             lr_end_transaction("获取天气预报", LR_PASS);
        }else{
             lr_end_transaction("获取天气预报", LR_FAIL);
        }
        
        
        //报错:Action.c(5): Error:HTTP Transport Provider function httpeng_request failed: rc=1001
        //原因: "URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",    地址错误,少了http
        //报错:Failed to connect to server "www.webxml.com.cn:80": [10060] Connection timed out
        //原因:连接断开需要重建脚本
        
        return 0;
    }

     第三种:

    Web_custom_request() 模式开发webservice 协议

    新建脚本选择webservice 协议

    使用函数web_custom_request

    http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName连接中查看接口信息

    Url:http://WebXml.com.cn//WebServices/WeatherWebService.asmx

     

    怎么获取报文信息:

    在无接口文档的前提下:就使用soapui 去获取接口需要的信息

     

    输入wsdl:    http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

     

  • 相关阅读:
    window
    pages
    百度小程序 配置 app.json 文件
    JavaScript Cookie
    jQuery ajax
    jQuery ajax
    jQuery ajax
    jQuery
    jQuery
    jQuery
  • 原文地址:https://www.cnblogs.com/michelle58/p/10750771.html
Copyright © 2020-2023  润新知