服务链接

http://ws.webxml.com.cn/WebServices/WeatherWS.asmx

可以复制到浏览器打开,建议先看下页面上的接口帮助文档,对接口有个大概的了解

webserivice接口loadrunner性能测试

获取soapui请求信息

笔者使用的soapui版本是soapUI Pro 4.0.1

下载地址为:链接:http://pan.baidu.com/s/1mifugMO 密码:pw13

  1. 新建soapui工程

    webserivice接口loadrunner性能测试

  2. 在Initial WSDL/WADL 输入框内输入服务地址+?wsdl,即"http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl"

    点击 OK 即可

    webserivice接口loadrunner性能测试

  3. 接着等待soapui导入接口,导入好之后如下图所示

    webserivice接口loadrunner性能测试

  • 4.我们选择getweather来做测试的示例,在theCityCode参数框内输入2414(城市编码可以通过getSupportCityString获得,这里就不做演示了),theUserID可以不填,点击提交按钮在右边就可以看到城市编码为2414的天气情况
  • webserivice接口loadrunner性能测试

5.点击soapui下方httplog,建议先右击清理掉当前信息

webserivice接口loadrunner性能测试

6.再次提交接口请求,然后将httplog中如下部分复制并编辑

webserivice接口loadrunner性能测试

编辑好如下所示,并保存为getweather.xml,截图中框起来的action信息另外记录下来:

action="http://WebXml.com.cn/getWeather"

webserivice接口loadrunner性能测试

文件内容如下:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">

<soap:Header/>

<soap:Body>

<web:getWeather>

<!--Optional:-->

 

<!--Optional:-->

 

<web:theCityCode>2414</web:theCityCode></web:getWeather>

</soap:Body>

</soap:Envelope>

到此为止,我们已经成功获取了soapui请求信息

 

其实还有一种超级简单的方式获取soapui请求信息,在

http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?op=getWeather

页面直接就有准备好的soapui请求信息,哈哈,但是通过以上操作,以后大部分webservice协议的接口即使没有已经准备好的报文信息,我们也可以自己制造了

webserivice接口loadrunner性能测试

Loadrunner生成脚本

  1. loadrunner新建脚本选择webservices协议

    webserivice接口loadrunner性能测试

  2. 导入脚本

    webserivice接口loadrunner性能测试

     

  3. 完善url和soapaction信息

    webserivice接口loadrunner性能测试

    url填入服务地址+?wsdl

    soap action填入上文保存的action信息

  4. 生成的脚本如下

    webserivice接口loadrunner性能测试

    内容如下:

    Action()

    {

     

     

        soap_request("StepName=SOAP Request",                                        

            "URL=http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl",                                        

            "SOAPEnvelope="

            "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://WebXml.com.cn/\">"

                "<soap:Header></soap:Header>"

                "<soap:Body>"

                    "<web:getWeather>"

                        "<web:theCityCode>2414</web:theCityCode>"

                    "</web:getWeather>"

                "</soap:Body>"

            "</soap:Envelope>",                                        

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

            "ResponseParam=response",                                        

            "Snapshot=t1497536280.inf",                                    

            LAST);

     

        return 0;

    }

脚本增强

参数化

选中citycode右击replace with a parameter

webserivice接口loadrunner性能测试

输入参数名称

webserivice接口loadrunner性能测试

打开参数化数据list

webserivice接口loadrunner性能测试

选择在记事本中编辑

webserivice接口loadrunner性能测试

添加好的参数如下

webserivice接口loadrunner性能测试

添加检查点

保存服务器响应参数,进行比较

切换到view tree模式,并选择response

webserivice接口loadrunner性能测试

找到接口返回的citycode,save value in parameter

webserivice接口loadrunner性能测试

弹窗点击OK即可

webserivice接口loadrunner性能测试

生成脚本如下:

    lr_xml_get_values("XML={response}",

     "FastQuery=/Envelope/Body/getWeatherResponse/getWeatherResult/string[3]",

     "ValueParam=ParamValue_string",

     LAST);

接着添加判断:

    if(strcmp(lr_eval_string("{ParamValue_string}"),lr_eval_string("{citycode}"))==0)

    {

        lr_output_message("Pass");

    }

    else{

        lr_output_message("Fail");

    }

备注:strcmp是C/C++函数,比较两个字符串设这两个字符串为str1,str2,若str1==str2,则返回零,可以百度了解一下

 

添加事务

在脚本开头插入开始事务

webserivice接口loadrunner性能测试

插入结束事务

在if判断成功处插入"成功"事务

webserivice接口loadrunner性能测试

在if判断失败处插入"失败"事务

webserivice接口loadrunner性能测试

最后的脚本如下

webserivice接口loadrunner性能测试

//getweather事务开始

    lr_start_transaction("getweather");

 

    //发送请求,并参数化citycode

    soap_request("StepName=SOAP Request",

        "URL=http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl",

        "SOAPEnvelope="

            "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://WebXml.com.cn/\">"

                "<soap:Header></soap:Header>"

                "<soap:Body>"

                    "<web:getWeather>"

                        "<web:theCityCode>{citycode}</web:theCityCode>"

                    "</web:getWeather>"

                "</soap:Body>"

            "</soap:Envelope>",

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

        "ResponseParam=response",

        "Snapshot=t1497536280.inf",

        LAST);

 

    //获取服务器相应参数,供后面判断事务成败

    lr_xml_get_values("XML={response}",

     "FastQuery=/Envelope/Body/getWeatherResponse/getWeatherResult/string[3]",

     "ValueParam=ParamValue_string",

     LAST);

 

    //根据服务器返回的citycode信息和请求中的citycode比对,判断事务成败

    if(strcmp(lr_eval_string("{ParamValue_string}"),lr_eval_string("{citycode}"))==0)

    {

        lr_output_message("Pass");

 

    lr_end_transaction("getweather", LR_PASS);

 

    }

    else{

        lr_output_message("Fail");

 

    lr_end_transaction("getweather", LR_FAIL);

 

    }

相关文章: