ripkurrle
4 years agoOccasional Contributor
DataSource Loop with variable number of child elements
Hi 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 probl...
- 4 years agoHey 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 >> datasource grid (with expanded data) event handler processes this data >> 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 xmlString = """<PROFILE> <NAME>Fin</NAME> <AGA>20</AGA> <CONTACT> <MOBILE>1819</MOBILE> <TELEPHONE></TELEPHONE> </CONTACT> <TEAM> <TEAM1></TEAM1> <TEAM2></TEAM2> </TEAM> </PROFILE>"""
def xml = new XmlParser().parseText(xmlString) def nodes = xml.'**'.findAll{it.name() && !it.text()} def removeNode = { node -> def parent = node.parent() parent.remove(node) } nodes.each{removeNode(it)} println groovy.xml.XmlUtil.serialize
Ta
Rich