Forum Discussion

natashanguyen42's avatar
natashanguyen42
New Member
6 years ago

extract xml node value from a response in script assertion

Hi All

 

Hi have a xpath match assertion that is working perfection as below

declare namespace ns1='http://${#Project#EndpointIP}/Subscription/V1/${DataSource#id_Request}';

//ns1:ATTRIBUTES//child::ns1:NAME [text() = ‘Result']//following-sibling::ns1:VALUE

 

Now I want to convert it to script typed assertion, the value of Result node is stored in variable named addResult as below

 

The problem I have here is that the addResult is always null.  And the assertion is always false.  Not sure why.  Can anyone help me to show where it is wrong?

 

Here is my code

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContentAsXml.toString())
responseHolder.namespaces["ns1"] = "http://" + context.expand("Project#EndpointIP") + "/SUBSCRIBER/V1/" + context.expand( '${DataSource#id_Request}' )
def addResult = responseHolder.getNodeValue("//ns1:ATTRIBUTES//child::ns1:NAME [text() = ‘Result']//following-sibling::ns1:VALUE")

if (addResult == context.expand( '${DataSource#IDRequest_RESPONSE}' )){
        log.info "matching here ->" + addResult
        assert true
}else{
       log.info "Not matching here ->" + addResult
       assert false
}

 

  • natashanguyen42, I see you contacted the Support Team, and they are waiting for additional info from you. Please share the solution with us when you have it :smileyhappy:

    Thank you!

  • nmrao's avatar
    nmrao
    Champion Level 3
    Would you please show the sample response and same structure (need not be actual) and what value to be extracted?
  • sonya_m's avatar
    sonya_m
    SmartBear Alumni (Retired)

    nmrao, thanks for your willingness to help! 

     

    natashanguyen42 , are you still facing this issue? If you are, please provide more details so the Community has more information to work with and we will try to help you. 

     

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      natashanguyen42, I see you contacted the Support Team, and they are waiting for additional info from you. Please share the solution with us when you have it :smileyhappy:

      Thank you!