Rest 如何在SoapUI中验证列表响应中是否存在项?

Rest 如何在SoapUI中验证列表响应中是否存在项?,rest,groovy,soapui,Rest,Groovy,Soapui,简短问题:在SoapUI/SoapUI Pro测试步骤中,如何验证作为列表的REST响应是否包含特定项 长版本:我有一个将两个REST方法调用链接在一起的测试套件。首先调用addCustomer,然后调用getCustomerByPhoneNumber。然而,电话号码不是唯一的,所以我可能会得到几个客户的名单。如何确定该列表是否包含我刚才添加的客户 示例:假设我调用addCustomer创建customer2,响应返回customerId=222。然后我调用getCustomerByPhoneN

简短问题:在SoapUI/SoapUI Pro测试步骤中,如何验证作为列表的REST响应是否包含特定项

长版本:我有一个将两个REST方法调用链接在一起的测试套件。首先调用
addCustomer
,然后调用
getCustomerByPhoneNumber
。然而,电话号码不是唯一的,所以我可能会得到几个客户的名单。如何确定该列表是否包含我刚才添加的客户

示例:假设我调用
addCustomer
创建
customer2
,响应返回
customerId=222
。然后我调用
getCustomerByPhoneNumber
,并收到以下响应。如何验证列表中是否存在
customerId=222
?理想情况下,我还希望验证有关
customer2
的所有信息是否正确(电话号码、姓名等)


111
顾客1
555-5555
222
顾客2
555-5555
333
顾客3
555-5555

如果答案需要Groovy脚本,我会很感激一些示例代码或伪代码,因为我以前从未使用过Groovy。

使用XPath,类似于
的东西存在(//*:customer[name[text()='customer2']])
,以查看“他”是否存在


接下来,类似于
/*:customer[name[text()='customer2']]/id的内容应该给您“222”。

您还可以在测试步骤上使用XQuery断言,如下所示:

for $customer in //*:customer
where ($customer/id = '222')
return ($customer/name,
        $customer/phone)
这将产生如下输出:

<name>customer2</name>
<phone>555-5555</phone> 
customer2
555-5555 
然后,在断言预期结果面板中,可以替换预期值:

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

如果您想在知道id的同时获取客户的所有信息,您可以使用类似这样的内容
/customers/customer/id[text()='222']/..
,然后您可以在xpath断言的上一个测试步骤中引用响应xml。谢谢!在我看到这个答案之前,我得到了一个非常类似的解决方案。我不知道如何单独使用XPath来实现,最后使用了一个XQuery断言,where子句引用addCustomer响应的ID字段。
<name>${customerName}</name>
<phone>${custmerPhone}</phone>