0

I'm trying to parse a bunch of ids out of an xml and loop over them to run some other test steps.

The xml basically boils down to this (removing all the extra):

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

My code is the below.

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

It will correctly give me those three values one by one, but then it will keep looping forever giving me blank values. I tried a number of different ways of passing the values into 'result' but nothing changed the situation.

I also tried just directly grabbing the values but no difference (example of that below)

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

}

Any advice on how to stop this infinite looping/passing in of blank values forever would be great.

EDIT: I also tried to match basically exactly what the example they give you does

// 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]
}
canpan14
  • 1,181
  • 1
  • 14
  • 36

1 Answers1

0

So this may be considered working around the issue, but I found a nifty little option under the DataSource options that when checked will stop running once the values are blank.

The option is called 'Skip Loop on Empty' and it worked for me.

enter image description here

canpan14
  • 1,181
  • 1
  • 14
  • 36