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