0

このようなWebサービスからの応答を取得しています。最初の入力では、このような3つのノードが得られます

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

2 番目の入力では、このように 2 つ以上の 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>

各ノードにアサーションを追加したいのですが、データ駆動型のテストを行っていますが、各リクエストのノード数がわからないので、どうすればこれを行うことができますか。

4

1 に答える 1

0

XML を解析する groovy スクリプトを作成できます。アサーションを作成する前に正確な応答がわからないためです。以下に、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 に答える