Ask a Question

extract xml node value from a response in script assertion

New Member

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 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}' )){ "matching here ->" + addResult
        assert true
}else{ "Not matching here ->" + addResult
       assert false


Community Hero

Would you please show the sample response and same structure (need not be actual) and what value to be extracted?

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 Mihaljova
Community and Education Specialist

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 Smiley Happy

Thank you!

Sonya Mihaljova
Community and Education Specialist

Showing results for 
Search instead for 
Did you mean: