2016-09-05 115 views
0

我想在XPath Assertions中斷言值(ActualCode)。我對JSON Path Assertion很有經驗,但是對於XML來說是全新的。我怎麼能在這裏聲明'ActualCode'值?Jmeter中的XML路徑斷言

<?xml version="1.0" encoding="UTF-8"?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
<S:Body> 
    <ns2:CreateValidCode xmlns:ns2="http://www.example.net/lmsglobal/ws/v1/extint/types" xmlns="http://www.example.net/lmsglobal/xsd/v1/types" xmlns:ns3="http://www.example.net/lmsglobal/ws/v1/extint/notification/types"> 
    <ns2:ValidCode>ActualCode</ns2:ValidCode> 
    <ns2:State>1</ns2:State> 
    </ns2:CreateValidCode> 

回答

1
  1. 創建的.properties文件,即namespaces.properties的地方,例如在JMeter.s 「bin」 文件夾。
  2. 添加以下行至namespaces.properties文件

    S=http://schemas.xmlsoap.org/soap/envelope/ 
    ns2=http://www.example.net/lmsglobal/ws/v1/extint/types 
    
  3. 添加下一行user.properties文件,它生活在JMeter的 「bin」 文件夾以及

    xpath.namespace.config=namespaces.properties 
    
  4. 重新啓動JMeter以提取屬性
  5. XPath Assertion添加爲請求的子項w HICH上述XML
  6. Use Namespaces
  7. 回報將下面的查詢進入 「的XPath斷言」 輸入:

    //ns2:ValidCode/text()='ActualCode' 
    

這應該是它。

有用的材料:

演示:

XPath Namespaces Demo

+0

謝謝!一個相關的小問題。如何將結果與變量相互配合?我嘗試了幾種方法,例如// ns2:ValidCode/text()= $ .Code,但它似乎不起作用。 – Mori

+0

已經算出來了! // ns2:ValidCode/text()='$ {Code}'是要走的路! – Mori