-1

I have a SOAP UI project that has the following web service response:

<env:Envelope env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <env:Header/>
   <env:Body>
      <m:invokeResponse xmlns:m="some namespace">
         <result xsi:type="xsd:string"><![CDATA[<?xml version="1.0" encoding="US-ASCII" standalone="yes"?><message><myVal>123</myVal></message>]]></result>
      </m:invokeResponse>
   </env:Body>
</env:Envelope>

I need to use an Assertion in SOAP UI to see that 123 is present which is in the XML in the CDATA section. I cannot just simply use a contains in SOAP UI Assertions as 123 might be present a couple of time witin the CDATA section. So I need to use XPath Assertion.

Now if I add an assertion XPath Match

//result/text()

It matches

<?xml version="1.0" encoding="US-ASCII" standalone="yes"?><message><myVal>123</myVal></message>

but if I change the expression to

//result[text()]/message/myVal[text()]

which should match 123 it fails

If I use a Script Assertion using groovy it works (I just used Groovy to see if it works)

import com.eviware.soapui.support.XmlHolder

respXmlHolder = new XmlHolder(messageExchange.getResponseContentAsXml())
respXmlHolder.declareNamespace("ns1","http://www.webserviceX.NET")

CDATAXml = respXmlHolder.getNodeValue("//result/text()")
CDATAXmlHolder = new XmlHolder(CDATAXml)

myval = CDATAXmlHolder.getNodeValue("//message/myVal")
assert myval == "123"

But I would like to know if there is a way to do this with an XPath Assertion inside SOAP UI. I need to handoff the project to Business that doesn't understand Groovy :)

cp5
  • 1,087
  • 6
  • 26
  • 58
  • Please check if this is going to help? http://stackoverflow.com/questions/19745210/what-xpath-to-select-cdata-content-when-some-childs-exist – Rao Feb 10 '15 at 15:45
  • If all else fails, try the documentation: http://www.soapui.org/functional-testing/working-with-cdata.html – SiKing Feb 10 '15 at 15:46
  • @SiKing The documentation explains what I did in my example, using Groovy, by using a Script to get the CDATA node and then create a new XmlHolder. And use that again with and XPath to get the desired value. – cp5 Feb 10 '15 at 19:05
  • @Rao - Thanks but that only selects the CDATA section as a string. I wanted to get a value inside the CDATA string which is an XML :) – cp5 Feb 10 '15 at 19:12
  • Did you see the section "4. XPath Assertions and CDATA"? – SiKing Feb 10 '15 at 19:44
  • @SiKing - I did it was where I learned about XmlHolder etc. But I wanted to know if there is a way to do this without using a script. The people who will maintain this is not programmers. And to expect them to understand how to write it is not fair to them. But thanks hey - it is worth reading.. – cp5 Feb 11 '15 at 06:47

3 Answers3

1

If I use a Script Assertion it's work for me hope it will work for you

import com.eviware.soapui.support.XmlHolder
responsexmlholder = new XmlHolder(messageExchange.getResponseContentAsXml())
Cdataxml = responsexmlholder.getNodeValue("//*:payLoad")
log.info Cdataxml
Cdataxmlholder = new XmlHolder(Cdataxml.trim())
errorcode = Cdataxmlholder.getNodeValue("//*:ErrorCode")
log.info errorcode
Dipiks
  • 3,818
  • 2
  • 23
  • 39
0

Looks like it is not possible to do this using XPath alone.

As XPath to the tag inside CDATA explain that the CDATA section is not parsed and it not possible to use an XPath expression to test if an element exists within the CDATA section

Community
  • 1
  • 1
cp5
  • 1,087
  • 6
  • 26
  • 58
  • 1
    Thats what mentioned in the link i sent you. And again there are ways to get the value, but not in the way you wanted. – Rao Feb 11 '15 at 03:45
  • @Rao you are absolutely correct. Not the way I would like it to... If you formulate an answer I will accept :) – cp5 Feb 11 '15 at 06:42
  • 1
    The response you posted itself says that is a string from . So xpath can't applied over a string. What is that stopping you "to handoff the project to Business"? I think you are fine as long as you send the valid response in the "result" element. Or you want to consider to change the schema for the response type (not encapsulate xml in the result) so that user can apply the xpath over it? – Rao Feb 11 '15 at 14:35
0

This is the most direct method we could come up with for verifying data within a CDATA block for a test case assertion. It flattens the xml to string and just looks for the string. Not that eloquent but it gets what we need done. It also uses a groovy script assertion.

import com.eviware.soapui.support.GroovyUtils
def rawResponse = messageExchange.getRawResponseData()
def rawResponseAsString = new String(rawResponse)
log.info rawResponseAsString
assert rawResponseAsString.contains('<myVal>123</myVal>')
Dan
  • 1
  • 1