Forum Discussion

mkaplan's avatar
mkaplan
Occasional Contributor
11 years ago

Groovy: Unexpected element: CDATA

Hi everyone,

I have a test request response and I'm trying to get a value from it using a groovy test step. I have said groovy step in a testsuite that goes through each step in order and it works perfectly. I also have a test suite where all test steps are ran from a groovy script. When I run the groovy test step to get the value from the response, I get "org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA".

It says the error is at line 3:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def response = context.expand('${initiateTransaction#Response}')
def holder = groovyUtils.getXmlHolder("response")

Why does the groovy test step fail when it's ran through another groovy test step?

Thanks,
Michael

6 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    There's nothing wrong with the expression groovyUtils.getXmlHolder("response"). Removing the quotes will fail, unless response is the name of a string variable.

    I think the problem is caused by the context variable "response" not holding the same value when you run it from your script as in the test suite. For instance, if the variable is empty (null), SoapUI will try to parse the string "null" as XML, which will throw the exception you reported.

    Try logging the value of the context variable and see if that gives you any clues:

    log.info(context.getProperty("response")

    /Manne
  • mkaplan's avatar
    mkaplan
    Occasional Contributor
    Hi thanks for replying!

    I wish that worked but it didn't. Quotes or no quotes it still fails when I run the step using groovy. The step will fail, I'll open it and run it, and it'll work.
  • mkaplan's avatar
    mkaplan
    Occasional Contributor
    Hi Manne,

    Thanks for the response. You were right, it's returning null. Also SiKing is also right now that I think about it, I do want to use the variable "response" that I created but that returns "" when I log it. I get what you're saying but now I don't understand why it's that way? Is this a known issue (Test step responses returning null/"" in a groovy script while being ran through another script)?

    Thanks,
    Michael

    Edit: When I have my code arranged as so:
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def holder = groovyUtils.getXmlHolder("initiateTransaction#Response")

    It works when I run the script manually or through a testcase, but not when ran through another groovy script like the code from my first post
  • IanWatson92's avatar
    IanWatson92
    Occasional Contributor
    Try
    def holder = groovyUtils.getXmlHolder("TestStepName#ResponseAsXml")
  • SiKing's avatar
    SiKing
    Community Expert
    mkaplan wrote:
    ... but not when ran through another groovy script ...

    Could you explain what the above means and give some detail.