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>