webService(SOAP)性能测试脚本

本文以天气预报的webService为基础进行学习

 
webService地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
操作步骤:
1、启动Jmeter后,新建线程组,然后添加一个WebService(SOAP) request取样器。
2、在WSDL URL栏目中输入:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
后点击“载入WSDL”,载入成功后就可以看到web Methods中有可选项的出现,这里面的可选项就是该服务中包含的用户可调用的方法。
3、选择一个方法后(例如:getSupportCity)后,点击"配置",此时,Jmeter会自动填充协议、服务器名称、端口、路径和SOAPAction字段,记得每次切换方法时都要重新点击“配置”一遍,生成新的配置
4、填写webService Message信息,这里填写的信息就是需要向服务器的SOAP请求信息,请求信息的格式可以在天气预报的帮助页面中看到,例如getSupportCity的请求和响应信息。http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getSupportCity

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebServices/WeatherWebService.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length:lengthSOAPAction: "http://WebXml.com.cn/getSupportCity"

<?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>
    <getSupportCity xmlns="http://WebXml.com.cn/">
      <byProvinceName>string</byProvinceName>
    </getSupportCity>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length:length<?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>
    <getSupportCityResponse xmlns="http://WebXml.com.cn/">
      <getSupportCityResult>
        <string>string</string>
        <string>string</string>
      </getSupportCityResult>
    </getSupportCityResponse>
  </soap:Body>
</soap:Envelope>

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebServices/WeatherWebService.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: application/soap+xml; charset=utf-8
Content-Length:length<?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>
    <getSupportCity xmlns="http://WebXml.com.cn/">
      <byProvinceName>string</byProvinceName>
    </getSupportCity>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length:length<?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>
    <getSupportCityResponse xmlns="http://WebXml.com.cn/">
      <getSupportCityResult>
        <string>string</string>
        <string>string</string>
      </getSupportCityResult>
    </getSupportCityResponse>
  </soap12:Body>
</soap12:Envelope>
我们只需要将请求信息中的文本信息输入Soap/XML-RPC data输入框中,并替换需要查询的信息
例如getSupportCity的可以输入一下信息获取广东省支持的城市
<?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>
    <getSupportCity xmlns="http://WebXml.com.cn/">
      <byProvinceName>广东</byProvinceName>
    </getSupportCity>
  </soap:Body>
</soap:Envelope>

注意在选项区域中勾选“读取SOAP响应”的复选框。
这样取样器的基本配置就完成了。
5、添加一个响应断言,响应字段选择“响应文本”,匹配规则选择“包括”,添加测试的模式,输入“深圳”。
6、添加一个断言结果监控器,之前建好一个CSV文件,在断言结果中选择该文件将数据保存在里面
,添加一个保存响应文本监控器(用户查看放回的数据是否正确)。
7、最后,点击运行,OK!!!完工!
运行完成后,查看断言结果监控器看是否正确,正确的话会只放回:WebService(SOAP) Request
如果错误的话,会提示错误原因例如:
WebService(SOAP) Request
 webservice_assue : Response was null
-------------------------------华丽的分隔线-------------------------------------------
再来看下CSV文件中保存的信息:
<sample t="218" lt="0" ts="1354524669558" s="true" lb="WebService(SOAP) Request" rc="200" rm="OK" tn="绾跨▼缁?1-1" dt="text" by="1052">
  <assertionResult>
    <name>webservice_assue</name>
    <failure>false</failure>
    <error>false</error>
  </assertionResult>
</sample>
这个的内容于Configure中选择的项有关。有点奇怪的是采用的了<failure>和<error>两个字段,这两个字段的值为false时则表示成功。这里跟一般人的思维有点绕,开始我就没反应过来,汗!
在看个响应结果保存文件(默认应该在启动目录中可以找到)
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getSupportCityResponse xmlns="http://WebXml.com.cn/"><getSupportCityResult><string>广州 (59287)</string><string>深圳 (59493)</string><string>潮州 (59312)</string><string>韶关 (59082)</string><string>湛江 (59658)</string><string>惠州 (59298)</string><string>清远 (59280)</string><string>东莞 (59289)</string><string>江门 (59473)</string><string>茂名 (59659)</string><string>肇庆 (59278)</string><string>汕尾 (59501)</string><string>河源 (59293)</string><string>揭阳 (59315)</string><string>梅州 (59117)</string><string>中山 (59485)</string><string>德庆 (59269)</string><string>阳江 (59663)</string><string>云浮 (59471)</string><string>珠海 (59488)</string><string>汕头 (59316)</string><string>佛山 (59279)</string></getSupportCityResult></getSupportCityResponse></soap:Body></soap:Envelope>
 
里面的信息就是getSupportCity(广东)的信息。如果需要获取里面市区的天气的话,就可以把这个所为一个关联的数据源获取值给变量赋值,可以使用正则表达式提取器。
posted on 2015-12-01 17:30  blogsheng  阅读(695)  评论(0编辑  收藏  举报