0

我正在尝试从 xml 中解析出一堆 id 并遍历它们以运行其他一些测试步骤。

xml 基本上归结为这一点(删除所有额外的):

<tr>
    <td>
        <a>11111</a>
    </td>
</tr>
<tr>
    <td>
        <a>11112</a>
    </td>
</tr>
<tr>
    <td>
        <a>11112</a>
    </td>
</tr>

我的代码如下。

// Defines the row to pass things in, will change based on iteration (hence the 'currentRow')
def row = testRunner.testCase.testSteps["DataSource"].currentRow
// Pulling in reponse
def responseAsXml = ***REST request xml response***
def xmlParser = new XmlSlurper().parseText(responseAsXml)
// Loading ids into list
def allIds = []
xmlParser.tr.each{ result ->
    allIds << result.td.a.text()

}
// Pass the next value into the ID property each time
allAccountIds.each{ id ->
        result["ID"] << id
}

它会一一正确地给我这三个值,但是它会一直循环给我空白值。我尝试了多种将值传递给“结果”的不同方法,但没有任何改变。

我也尝试直接获取值但没有区别(下面的示例)

xmlParser.tr.each{ result ->
    result["ID"] << result.td.a.text()

}

关于如何永远停止这种无限循环/传入空白值的任何建议都会很棒。

编辑:我也试图基本上完全匹配他们给你的例子

// Loading in ids into list
def allIds = []
xmlParser.tr.each{ result ->
    allIds << result.td.a.text()

}
// Pass the next value into the ID property each time
if((row +1) <= allIds.size){
    result["ID"] << allIds[row]
}
4

1 回答 1

0

所以这可以考虑解决这个问题,但我在 DataSource 选项下发现了一个漂亮的小选项,一旦选中,一旦值为空,它将停止运行。

该选项称为“空时跳过循环”,它对我有用。

在此处输入图像描述

于 2017-04-27T19:24:41.437 回答