Ask a Question

DataSource Loop with variable number of child elements

Occasional Contributor

DataSource Loop with variable number of child elements


I've just started using ReadyAPI 3.4.5 after being on SoapUI for a while.

I'm testing an external vendor API and trying to pass in all my scenario data through one DataSource, ideally.

My problem is that each of the test cases has a different number of elements applied to a complex element, e.g. Test 1 may have the following elements for specifying contributions












The next test might only have one Single contribution defined. There are a few complex elements that I adjust for each test and have a similar problem.


I've set the flag for "Remove Empty Content" to try and remove any elements where nothing is passed in from the DataSource but this leaves the parent node empty "<contribution></contribution>" which unfortunately breaks the test.


I've researched ways that this might be able to be resolved using Events with RequestFilter.filterRequest but the supplied groovy script doesn't appear to work well with DataSource data, instead it passes the property name in as a string to the request, e.g. ${DataSource#Single-Amount}

See section 4.5 in and

Seems like a similar issue was raised here but the user didn't confirm whether it fixed their problem or not 


The only way I can think of getting around this is not using the DataSource at all and, instead, crafting each test step as a specific test. I'm not a tester by profession so perhaps this is the way more seasoned testers craft tests when they have these limitations, I just wanted to control the test data from the one view point.


I also thought a RegEx over the expanded request, with DataSource data populated in, just before it gets sent I could replaceAll some of the fields but couldnt work out an event or script to get the XML at this point.




Community Hero

Hey @ripkurrle,

I wouldve picked the same event handler you did to handle the empty root element, but ive never tried events on datasourced data before.

Rather than have to go with the individual test data approach on each test step, im wondering if perhaps your datasource step passed the data to a datasource grid (as an intermediate step before being sourced by the Rest step, perhaps this would work? I know the datasource grid is a datasource step, but it might work?

I.e. datasource step &gt;&gt; datasource grid (with expanded data) event handler processes this data &gt;&gt; REST step sources data from datasource grid

Or, i'm wondering if you have a datasource that writes to a properties file, groovy step to remove the empty elements and then the REST step (sourcing the data from the Properties step via ${Properties#testdata}) to submit the request which doesnt contain any empty elements? Actually id do it this way i think, so my test step object hierarchy would be as follows:

Datasource step
Properties step
Groovy step
Properties2 step (optional)
REST step

Groovy step would contain something like the following (code = courtesy of


def xml = new XmlParser().parseText(xmlString) def nodes = xml.'**'.findAll{ &amp;&amp; !it.text()} def removeNode = { node -&gt; def parent = node.parent() parent.remove(node) } nodes.each{removeNode(it)} println groovy.xml.XmlUtil.serialize


if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Occasional Contributor

Thanks Rich, I'll give it a go.

SmartBear Alumni (Retired)

Thanks for the help, richie!

@ripkurrle, was the issue resolved? Please let us know if you need more help.

Tanya Yatskovskaya
SmartBear Community and Education Manager

Occasional Contributor

Apologies, I was on leave last week.


I'm putting together a simpler isolated test against this API to prove richie's theory.

Occasional Contributor

Unfortunately, I cant find a public SOAP API that accepts an optional number of inputs to make this easier to see.

Occasional Contributor


I've found an easier scenario I can test this on and setup the test case to use a DataSource type Grid (similar to my original test case with 5 attributes and one of those optional) and other steps below.


@richie Apologies but I'm unsure what to do with the properties steps, still new to this. The Groovy script appears to need the request just before its sent out the door to remove those empty elements but I'm unsure how a Property Step (or Property Transfer?) would help get it into this state.



Get MLAs List service currently returns an empty parent tag after the empty mlaid element was removed by the case level remove empty element flag.


<soapenv:Envelope xmlns:soapenv="">



Here is a picture of the two scenarios in the Grid, second one has the empty element you can see above.






Showing results for 
Search instead for 
Did you mean: