Showing results for 
Search instead for 
Did you mean: 

Groovy datasource looping


Groovy datasource looping

Take a look at this Groovy datasource code:


import fwa.soapui.*
import groovy.sql.*

// Execute a query and return a list of results
JdbcUtilities j = new JdbcUtilities(driver: context.expand('${#Project#driver}'), connectionStr: context.expand('${#Project#connectionStr}'))
List results = j.getData()

for (row in results) {
	result["TAB"] = row.getAt("TAB").toString()
	result["SPCT"] = row.getAt("SPCT").toString()
	result["TYPE"] = row.getAt("TYPE").toString()
	result["ID"] = row.getAt("ID").toString()

j.closeConnection() "Hello"

I understand that there are JDBC steps in SoapUI that can execute queries, but for reasons I won't get into, I need to execute this from an external Groovy library. Anyways, when I run this for say, 10 maximum rows, "Hello" is printed out to the log 10 separate times.


Is this entire block of Groovy code executed for each loop? If that is the case then this SQL connection is opened and closed repeatedly -- I was hoping this would simply open my connection once, loop over each row in my results, then close the connection, but that does not seem to be the case.


Can anyone shed some light on how these Groovy datasource loops actually work? It's also very possible that I might be misusing them.

Top Kudoed Authors