【JMeter4.0學習(三)】之SoapUI創建WebService接口模擬服務端以及JMeter對SOAP協議性能測試腳本開發


目錄:

 

 

 

 

【闡述】:首先應該遇到了一個共同的問題,JMeter3.2之后就沒有WebService(SOAP) Request,后來經過查詢網上資料得知其實可以用HTTP請求來操作,結果是一樣的。

具體資料大家可以參照原文《Jmeter測試SOAP協議(Jmeter 3.3)》感謝作者:stone9159

【步驟】:

一、創建WebService接口模擬服務端

如果大家有接口地址是最好啦,不過本人因為沒有接口地址,所以就自己手動模擬創建WebService接口模擬服務端。

參考資料:《SoapUI5.0創建WebService接口模擬服務端》感謝作者:sean-zou

1、首先,需要下載SoapUI

官方下載地址:https://www.soapui.org/downloads/latest-release.html

下載后,一直點擊下一步進行安裝就可以啦,在此不必陳述。

2、使用SoapUI創建WebService接口模擬服務端需要接口描述文件

新建文件:MathUtil.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://sean.com" 
        xmlns:apachesoap="http://xml.apache.org/xml-soap" 
        xmlns:impl="http://sean.com" 
        xmlns:intf="http://sean.com" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <schema elementFormDefault="qualified" 
          targetNamespace="http://sean.com" 
          xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="add">
    <complexType>
     <sequence>
      <element name="x" type="xsd:int"/>
      <element name="y" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
   <element name="addResponse">
    <complexType>
     <sequence>
      <element name="addReturn" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>
   <wsdl:message name="addResponse">
      <wsdl:part element="impl:addResponse" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:message name="addRequest">
      <wsdl:part element="impl:add" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:portType name="MathUtil">
      <wsdl:operation name="add">
         <wsdl:input message="impl:addRequest" name="addRequest">
       </wsdl:input>
         <wsdl:output message="impl:addResponse" name="addResponse">
       </wsdl:output>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="MathUtilSoapBinding" type="impl:MathUtil">
      <wsdlsoap:binding style="document"
              transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="add">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="addRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="addResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="MathUtilService">
      <wsdl:port binding="impl:MathUtilSoapBinding" name="MathUtil">
         <wsdlsoap:address 
                 location="http://localhost:8080/webservice_create/services/MathUtil"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

3、打開SoapUI,通過MathUtil.wsdl文件在SoapUI中創建一個SOAP項目:

確認后,會在新建的SOAP項目下自動生成模擬客戶端

在模擬客戶端的基礎上創建一個接口模擬服務端(Mock Service):

確定后,雙擊【Response1】

 

返回值默認為"?",一定要進行修改,否則調用該接口時會報錯

4、接口模擬服務端配置以及啟動

雙擊創建的接口模擬服務端,點擊【設置】按鈕:

 把地址可以自己定義,然后確定:

 再返回點擊運行按鈕,啟動服務器

 在瀏覽器中輸入ip和端口號:

 

再點擊鏈接:

 

此時,創建WebService接口模擬服務端完成!

 

二、JMeter對SOAP協議性能測試腳本開發

如圖所示,建立線程組、HTTP信息頭管理器、HTTP請求、查看結果樹等

1、建立線程組

2、建立HTTP信息頭管理器

 在“HTTP信息頭管理器”中,添加一行名稱和值,來源於如下圖:

Content-Type: text/xml;charset=UTF-8

 

 3、建立HTTP請求

填寫服務器IP、端口號、HTTP方法、路徑、編碼,以及打開“Body Data”

Body Data內容填寫:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sean="http://sean.com">
   <soapenv:Header/>
   <soapenv:Body>
      <sean:add>
         <sean:x>?</sean:x>
         <sean:y>?</sean:y>
      </sean:add>
   </soapenv:Body>
</soapenv:Envelope>

 4、建立監聽器並運行查看結果

運行之后,查看結果樹:

測試成功!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM