0

我从这样的网络服务中得到响应,对于第一个输入,它给了我三个这样的节点

        <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 Nodes ,就像这样

        <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>

我想为每个节点添加断言,我正在做数据驱动测试,我不确定每个请求的节点数量,所以我该如何做到这一点。

4

1 回答 1

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
于 2012-11-07T13:25:57.367 回答