Showing results for 
Search instead for 
Did you mean: 

Looping through datasource and xml response in Groovy

Occasional Contributor

Looping through datasource and xml response in Groovy


I have an Excel DataSource containing more than 12000 records with only the properties AdvisorIds and AdvisorNames. I also run a Soap request with a response containing the same records. Now I want to cross-reference the DataSource with the Soap Response. I started writing a groovy script to do this. I used some information from this post: :


def response= context.testCase.testSteps["GetAdvisors2"].getPropertyValue("response").toString()
def xmlResponse = new XmlSlurper().parseText(response)

def countAdvisors = xmlResponse.advisor.size()

dataSource = testRunner.testCase.getTestStepByName('DataSource').repositionAtStartRow(testRunner, context)

for (row in 0..dataSource.rowCount -1){
if (row > 1)

def dataSourceAdvisorsId = dataSource.getPropertyValue('ADVISORID')
def dataSourceAdvisorsName = dataSource.getPropertyValue('ADVISORNAME')

for(i=0; i<countAdvisors; i++){

def advisorIdXmlResponse =[i].text()
def advisorNameXmlResponse =[i].text()
} "AdvisorsId xmlResponse = " + advisorIdXmlResponse "AdvisorsName xmlResponse = " + advisorNameXmlResponse

assert dataSourceAdvisorsId == advisorIdXmlResponse
assert dataSourceAdvisorsName == advisorNameXmlResponse


Unfortunately the rowCount method returns 1 instead of 12000. The loop for the xmlSlurper (starting with for(i=0; i<countAdvisors; i++){) is working and looping through the Ids and Names. Is there a way of using this groovy script to get both al the rows from the DataSource, iterate through it and at the same time iterate throught the Soap Response?

Thanks in advance!



Community Hero

Re: Looping through datasource and xml response in Groovy

Hi @koen_able ,


If it is possible can you attach your response, because code seems correct, i think the problem is with response structure and the way you are getting size.


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓

Thanks and Regards,
Himanshu Tayal

Re: Looping through datasource and xml response in Groovy

Hi all,


@koen_able, have you managed to find a solution? If so, could you please share your results?
Otherwise, can you attach the response as @HimanshuTayal requested?
We are looking forward to hearing from you!


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Top Kudoed Authors