Forum Discussion

mcgintym's avatar
mcgintym
Occasional Contributor
16 years ago

getNodeValue is not passing the value from XPath to variable

Has anyone seen this issue.  When asserting a value from a database property vs. a holder.getNodeValue.  The getNodeValue is not passing the value as expected? 

Here is my groovy script assertion

//Compare values in XML response with property values taken from the database
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent );
//Get nodeValue - "Id"
def responseId = holder.getNodeValue["//ns2:getServicePResponse/ns2:getServicePReturn/serviceP/id"];
//get value from test step for comparison db retrieval
def propId = context.getProperty( "getIdfromDB", "DbId" );
//assert Comparison on captured values
assert (responseId == propId);
log.info responseId+" "+propId

The message I get is

Expression: (responseId == propId). Values: responseId = [], propId = 123456789

You can see the responseID is []  Can someone help me figure out what I am missing?


The XML Response is below...


 
     
       
           
              123456789
              2001-08-01-04:00
              2005-07-31-04:00
              Happy
              Action Explicit
              Retail
              No Longer Employed
             
                  2001-08-01-04:00
                  2001-10-31-05:00
             

           
>
       

     

 



Any help would be appreciated

Thanks

13 Replies

  • mcgintym's avatar
    mcgintym
    Occasional Contributor
    Thanks for the update,  Question though.  I have all of this but the question might be since I am a bit new to SOAP UI

    Your line ---> holder = groovyUtils.getXmlHolder("#Response");
    I have this
    def requestHolder = groovyUtils.getXmlHolder( messageExchange.requestContent );

    Question about REQUEST NAME?  Should it be something else?  SO far I am still not bringing back a value

    Thanks for your help

    Regards
  • sinnes_1's avatar
    sinnes_1
    Occasional Contributor
    I'm not sure what messageExchange.requestContent is.

    You need to replace with the actual name of your soap request. I know by default when you make the test step, it's called "Test Request". So it's quite literally the name of your Request test step. I couldn't put in, because I didn't know what it was
  • tpowers's avatar
    tpowers
    Occasional Contributor
    Might either of you have suggestions for reading properties from a request formatted like this?

    This is the way it comes from the client.... I cannot alter it (other than the ns name).

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
       <SOAP-ENV:Body>
          <RunScript xmlns="http://tempuri.org/">
             <optionObject>
                <EntityID>5</EntityID>
                <Facility>98</Facility>
                <Forms>.....


    Currently I have this which returns null...
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )

    context.EntityID = holder.getNodeValue( "//EntityID")
    context.EntityID = holder.getNodeValue( "//Facility")


    Any help is greatly appreciated...

    -Tim


    MODIFIED POST

    Thanks to M McDonald for the solution to my issue above, I needed to declare a 'temp' ns above for use in the script.



    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( xml )
    holder.declareNamespace( 'ns', 'http://tempuri.org/') //add this declaration

    log.info holder.getNodeValue( "//ns:Facility") //add 'ns' prefix
    log.info holder.getNodeValue( "//ns:EntityID")