cancel
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

Hi,

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: https://community.smartbear.com/t5/SoapUI-Pro/Looping-a-Datasource-in-Groovy-script-Always-starts-at... :

 

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)
{
testRunner.testCase.getTestStepByName('DataSource').Next
}

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

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

def advisorIdXmlResponse = xmlResponse.advisor.id[i].text()
def advisorNameXmlResponse = xmlResponse.advisor.name[i].text()
break;
}
log.info "AdvisorsId xmlResponse = " + advisorIdXmlResponse
log.info "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!

 

 

2 REPLIES 2
Community Leader

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, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Moderator

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:
API Testing Mistake #2
APITestingMistake#2