webserivice接口loadrunner性能测试

服务链接

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

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

获取soapui请求信息

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

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

  1. 新建soapui工程

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

    点击 OK 即可

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

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

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

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

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

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

文件内容如下:

<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协议的接口即使没有已经准备好的报文信息,我们也可以自己制造了

Loadrunner生成脚本

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

  2. 导入脚本

     

  3. 完善url和soapaction信息

    url填入服务地址+?wsdl

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

  4. 生成的脚本如下

    内容如下:

    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

输入参数名称

打开参数化数据list

选择在记事本中编辑

添加好的参数如下

添加检查点

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

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

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

弹窗点击OK即可

生成脚本如下:

    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,则返回零,可以百度了解一下

 

添加事务

在脚本开头插入开始事务

插入结束事务

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

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

最后的脚本如下

//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);

 

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值