header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
November 21, 2008, 07:15:55 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
Assert using XPath in XML contained in CDATA
Welcome, Guest. Please login or register.
November 21, 2008, 07:15:55 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  Assert using XPath in XML contained in CDATA
« previous next »
Pages: [1] Print
Author Topic: Assert using XPath in XML contained in CDATA  (Read 587 times)
Tareque
Newbie
*
Posts: 17


« on: November 16, 2007, 05:06:18 pm »

Hi Ole,
I am trying to add XPath assertions to validate the data that I am getting in a request that has an XML as one of the tag values enclosed in CDATA section. I am able to do it using this Groovy script,
def request = testRunner.testCase.getTestStepByName("AsyncMockResponse").getProperty("request");
println "\n Async Request "
def node = new groovy.util.XmlParser(false,false).parseText(request.value);
def input = node["soapenv:Body"]["ns1:processRequest"]["incomingXml"]
def requestXml = new groovy.util.XmlParser(false,false).parseText(input.value);
def tagValue = requestXml.children()["error-code"]
println tagValue.value.toString()
if(tagValue.value.toString() == '[144]'){
   println "You passed"
}else{
   println "You failed"
   throw new Exception("You failed")
}

Is there a better way to do it using just XPATH.
Regards


PS. I am also attaching a snippet of the XML that I am trying to validate.
<ns1:processRequest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:WSDLGateway" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <incomingXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><![CDATA[<ovm xmlns="http://next.com/ovm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://next.com/ovm http://localhost:8000/ovm/xsd/ovm-response.xsd">
    <ovm-error-info>
        <error-type>2</error-type>
        <error-code>144</error-code>
        <error-details>This is a corporate/government order, but no corporate/government identifier was sent.</error-details>
    </ovm-error-info>
</ovm>]]></incomingXml>
  <dealer xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
  <msgType xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
  <systemIndicator xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
</ns1:processRequest>
Logged
Tareque
Newbie
*
Posts: 17


« Reply #1 on: November 19, 2007, 10:00:49 pm »

Hi,
I was able to make the groovy script simpler by introducing a PropertyTransfer and a Properties object. The groovy script now is as follows

def utils = new com.eviware.soapui.support.GroovyUtils(context)
def value = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("XML")
def holder = utils.getXmlHolder(value)
assert holder.getNodeValue("//ns1:ovm-error-info/ns1:error-code") == '254'


Is this a good approach or is there a better way to do this.
Regards
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,420


« Reply #2 on: November 20, 2007, 12:19:37 am »

Hi!

This looks like a fine approach to me :-)

regards!

/Ole
eviware.com
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header