我收到了像这样的webservice的响应,第一次输入它给了我这样的三个节点
<m:tPlayerNames>
<m:iId>16</m:iId>
<m:sName>Adam Matuszczyk</m:sName>
<m:sCountryName>Poland</m:sCountryName>
</m:tPlayerNames>
<m:tPlayerNames>
<m:iId>588</m:iId>
<m:sName>Adil Rami</m:sName>
<m:sCountryName>France</m:sCountryName>
</m:tPlayerNames>
对于第二个输入,我得到两个以上的tPlayerNames节点,比如
<m:tPlayerNames>
<m:iId>16</m:iId>
<m:sName>Adam Matuszczyk</m:sName>
<m:sCountryName>Poland</m:sCountryName>
</m:tPlayerNames>
<m:tPlayerNames>
<m:iId>588</m:iId>
<m:sName>Adil Rami</m:sName>
<m:sCountryName>France</m:sCountryName>
</m:tPlayerNames>
<m:tPlayerNames>
<m:iId>552</m:iId>
<m:sName>Zlatan Ibrahimovic</m:sName>
<m:sCountryName>Sweden</m:sCountryName>
</m:tPlayerNames>
我想为每个节点添加断言,我正在进行数据驱动测试,我不确定每个请求的节点数,所以我可以这样做。
答案 0 :(得分:0)
您可以创建一个groovy脚本来解析XML。因为在创建断言之前你不知道确切的响应。在下面,您可以找到解析xml响应并查找元素的脚本
def response = context.expand( '${Test Request#Response#declare namespace soap=\'http://www.w3.org/2003/05/soap-envelope\'; //soap:Envelope[1]}' )
def responseParser = new XmlParser().parseText(response)
def allNodes = responseParser.children()
def nodeToFind=responseParser.nodeOfResponse.find { it.text() == 'text' }
log.info nodeToFind