Forum Discussion

ArturoMartinez's avatar
ArturoMartinez
Occasional Contributor
12 years ago

Extract info from XML returns null

Hi @ll!

I'm new to SoapUI and to Groovy Scripts.
So far, I've read some tutorials and I'm trying to launch my own TestSuite.
This suite just have a TestCase with 2 TestSepts, 'Ping' and 'Script'.
After Ping (wich runs ok) I want my script to get response and parse through XML nodes and get 'return' node.

Ok, so here's the XML response by 'Ping':

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dlwmin:PingResponse xmlns:dlwmin="http://dvtransaction.com/">
<return>System is loaded</return>
</dlwmin:PingResponse>
</soapenv:Body>
</soapenv:Envelope>

And here's the 'Script's code:

def tsuite = testRunner.testCase.testSuite;
def tcase = tsuite.testCases["FirstTestCase"];
def tstep = tcase.getTestStepByName("PingTest");

def gutils = new com.eviware.soapui.support.GroovyUtils( context );
if (gutils != null)
{
def holder = gutils.getXmlHolder(tstep.getPropertyValue("response"));
if ((holder.hasProperty('xml')) && (holder != null))
log.info(holder.getNodeValue('return'))
else
log.info('error: holder is null or has no property xml');
}
else
log.info('error: gutils is null');


But it always returns 'null'.

Thanks for your responses in advance.

3 Replies

  • ArturoMartinez's avatar
    ArturoMartinez
    Occasional Contributor
    Ok, I think I'm on the right way, but no sure ... at all.

    This is how I've managed to know that 'return' node got length equal 0.

    def tsuite = testRunner.testCase.testSuite;
    def tcase = tsuite.testCases["FirstTestCase"];
    def tstep = tcase.getTestStepByName("PingTest");

    def gutils = new com.eviware.soapui.support.GroovyUtils( context );
    if (gutils != null)
    {
    def holder = gutils.getXmlHolder(tstep.getPropertyValue("response"));
    if ((holder.hasProperty('xml')) && (holder != null))
    {
    if (!holder.empty)
    {
    def node = holder.get('return');
    if ((node != null)&&(node.length != 0))
    log.info(node.value);
    else
    log.info("error: <return /> doesn't exists or length equals 0");
    }//fi:!empty
    else
    log.info('error: XML response is empty')
    }//fi:!null
    else
    log.info('error: holder is null or has no property xml');
    }
    else
    log.info('error: gutils is null');


    Any suggest?
  • Hi,
    I can't say what is wrong with your code without testing it, but over all you complicate to much the response extraction and parsing, there are more ways to parse the xml holder and if you do an search on the forum you will get more solutions.

    A simple should be is this:
    import com.eviware.soapui.support.xml.XmlUtils
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    xmlResponseHolder = groovyUtils.getXmlHolder("PingTest#Response")
    retunValue = xmlResponseHolder.getDoomNode('//return/text()').nodeValue
    log.info retunValue


    Hope this will help you.
  • ArturoMartinez's avatar
    ArturoMartinez
    Occasional Contributor
    ccdssv1 wrote:
    Hi,
    I can't say what is wrong with your code without testing it, but over all you complicate to much the response extraction and parsing, there are more ways to parse the xml holder and if you do an search on the forum you will get more solutions.
    [ ... ]
    Hope this will help you.


    Yes, it works!
    Thank you.