Forum Discussion
We would definitely need to see more to accurately troubleshoot the groovy script you have. You could also use an XPATH assertion with
count(//*:nonExistentElement) and set it to be 0
Otherwise I'd think we'd need to see your response if it has to be done via groovy.
- DouglasY7 years agoOccasional Contributor
I'm sorry that my plea for assistance is so unhelpful. This kind of reaction is why I seldom post to community forums. I already feel like an idiot because I can't figure it out on my own. If a community hero cannot understand me, maybe I should keep away.
I want a groovy solution. Rather than the response, I think you want to see my request XML. The scripts I have are checking the request for existence of an XML element, which in my example I named nonExistentElement, then doing different validations on the response based on what answer comes back about how the request was formulated. The construct as I present in my sample code appears many times in many different scripts, and they are all generating errors which I would like to clean up.
Whether I use the context expansion with an exact XPath, or one with wildcards as I have given, when the element is not there, I get a null back, which is all fine and good for the working of the script conditional branching; however, I also get an annoying error in the error logs and the Ready API logs about "Unexpected element: CDATA". I want to eliminate the error by some means.
I would like some way to evaluate in the groovy script whether an Xpath exists or not, but without generating an error in the case where the Xpath does not exist.
- groovyguy7 years agoChampion Level 1
Don't take our asking questions as a personal attack. We're here to help. We just may need more information; that does not reflect at all poorly on you.
As for the groovy script, try this:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); def request = groovyUtils.getXmlHolder( messageExchange.requestContentAsXml ) def response = messageExchange.getResponseHeaders().toString(); int currValue = request["count(//*:nonExistentElement)"].toInteger(); assert currValue == 0;
- nmrao7 years agoChampion Level 3groovyguy, the above solution only works if there is no CDATA in the xml. Some response xml has an xml wrapped under CDATA and it may not work in such situations.
For example:
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/CdataInsideXml.groovy
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/CdataXpathExists.groovy
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/XmlInsideCdata.groovy
- nmrao7 years agoChampion Level 3
Solution can be derived or try to achieve it only if the problem is reproduced.
You are in need and not sure if attention is paid to the requested information in the previous reply. Don't let others assume / image the problem as that is going to delay in getting near to solve the problem.