2014-06-10 26 views
0

簡短問題:在SoapUI/SoapUI Pro測試步驟中,如何驗證列表的REST響應是否包含特定項目?如何驗證一個項目是否存在於SoapUI的列表響應中?

長版本:我有一個測試套件將兩個REST方法調用鏈接在一起。首先我撥打addCustomer,然後我撥打getCustomerByPhoneNumber。但是,電話號碼不是唯一的,所以我可能會找回幾個客戶的名單。我如何確定該列表是否包含我剛剛添加的客戶?

示例:假設我打電話addCustomer創建customer2,並且響應返回customerId = 222。然後我打電話getCustomerByPhoneNumber並收到以下回復。我如何驗證customerId = 222是否存在於列表中?理想我也想驗證所有有關customer2是正確的(電話號碼,姓名等)

<customers> 
    <customer> 
     <id>111</id> 
     <name>customer1</name> 
     <phone>555-5555</phone> 
    </customer> 
    <customer> 
     <id>222</id> 
     <name>customer2</name> 
     <phone>555-5555</phone> 
    </customer> 
    <customer> 
     <id>333</id> 
     <name>customer3</name> 
     <phone>555-5555</phone> 
    </customer> 
</customers> 

如果答案需要Groovy腳本,我會很感激一些示例代碼或僞代碼,因爲我以前沒有使用過Groovy。

回答

0

你也可以在測試步驟是這樣使用的XQuery斷言

<name>customer2</name> 
<phone>555-5555</phone> 

然後,在斷言預期的效果面板,您可以代替預期值:

<name>${customerName}</name> 
<phone>${custmerPhone}</phone> 
+0

謝謝!在我看到這個答案之前,我遇到了非常類似的解決方案。我無法弄清楚如何單獨使用XPath並結束使用XQuery斷言,其中where子句引用addCustomer Response的ID字段。 – GeekChick

0

使用XPath,如exists(//*:customer[name[text()='customer2']]),查看是否存在「他」。

接下來,類似//*:customer[name[text()='customer2']]/id應該給你「222」。

for $customer in //*:customer 
where ($customer/id = '222') 
return ($customer/name, 
     $customer/phone) 

這將產生輸出,如::

+0

而且,如果你想知道讓我們說id的同時抓住客戶的所有信息, ld使用像這樣的'/ customers/customer/id [text()='222']/..'然後你可以在xpath斷言中的前面的測試步驟中引用響應xml。 – nwill001

相關問題