Ask a Question

Using multiple rows of a Data Source in a single TestRequest step

Mike_M
New Contributor

Using multiple rows of a Data Source in a single TestRequest step

Does anyone know of a relatively simple way to consume multiple rows of a Datasource in one Test Request step?

The scenario here being able to combine multiple rows in a worksheet into a single batch request without "denormalizing" the worksheet data.
5 REPLIES 5
omatzura
Super Contributor

Hi,

there is no really easy way to do this currently; you will need to create a groovy script that manually builds the entire XML block by calling the next( testRunner, context ) method of the DataSource step to get the next row, something like

def xml = ...

def dataSource = testRunner.testCase.testSteps["DataSource"]
while( dataSource.next() )
{
    xml += .. add to xml block..
}

context.blockOfXml = xml

and then use this variable with

${blockOfXml}

in your request..

Hope this helps!

regards,

/Ole
eviware.com
Mike_M
New Contributor

Thanks for the reply.

When I try 'dataSource.next' however I get the following:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep.next() is applicable for argument types: () values: {}

Do I need to cast dataSource to a different type?
omatzura
Super Contributor

Hi!

sorry, my mistake.. the call should be

next( testRunner, context )

sorry, hope this helps!

regards,

/Ole
eviware.com
Mike_M
New Contributor

Thanks again.

I ended up turning the rows of data into XML in a Groovy step, but I assigned it to a property, then used property expansion to place the relevant data in the request (see below.)

What I should do is read the list of properties from the DataSource and build the XML generically.

Groovy script:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def dataSource = testRunner.testCase.testSteps['DataSource']

def xml = ''
while( dataSource.next( testRunner, context ) )
{
    xml += ''
    xml += '' + groovyUtils.expand('${DataSource#OrderID}') + ''
    xml += '' + groovyUtils.expand('${DataSource#OrderName}') + ''
    xml += '
'
}
xml += '
'

groovyUtils.setPropertyValue("Properties","xml", xml)


Request fragment:


 
    ${Properties#xml#//dataRow[1]/OrderID/text()}
    ${Properties#xml#//dataRow[1]/Name/text()}
 

 
    ${Properties#xml#//dataRow[2]/OrderID/text()}
    ${Properties#xml#//dataRow[2]/Name/text()}
 

omatzura
Super Contributor

Great!

Thanks for sharing your solution, this is not an unusual setup and I'm sure others will be able to use this..

regards,

/Ole
eviware.com
cancel
Showing results for 
Search instead for 
Did you mean: