Forum Discussion

jtheuer's avatar
jtheuer
Occasional Contributor
16 years ago

groovy script, property transfer, Unexpected element: CDATA.

Hi, for some hours now, I try to transfer a JSON property from one Response as JSON property for a following test. Sadly, it doesn't work with the PropertyTransfer method: I followed the steps from http://www.soapui.org/userguide/functio ... sfers.html but when I click "define namespaces" I get "Property source is not a request" which looks like http://www.soapui.org/xref/com/eviware/ ... .html#1185 .

Now I try the groovy script to transfer the property. first, here is the response as xml:

<Response xmlns="http://localhost/service/_tempfile/">
  <error/>
  <httpStatus>200</httpStatus>
  <url>17d091f8da3f8f464147f8f9103e589f</url>
</Response>

I want to transfer the url field. I copyied again some groovy code from the documentation:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );

// create holder for last response and log requestId
def holder = groovyUtils.getXmlHolder( "upload simple tour#Response" )
log.info( holder.getNodeValue( "//ns1:httpStatus" ))

But the code already stucks at "def holder": XmlBeansException: Unexpected element: CDATA.

Can someone help me? what is this CDATA issue about? There is no CDATA field in the Response, as far as I can see...

Thanks,

Jan
  • Hi Jan,

    you need to use the ResponseAsXml source property (instead of just "Response") to get the xml version, either from your script or in your property transfer.

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • jtheuer's avatar
    jtheuer
    Occasional Contributor
    Thanks, that code works:


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );

    // create holder for last response and log requestId
    def holder = groovyUtils.getXmlHolder( "upload simple tour#ResponseAsXml" );
    def p_url = holder.getNodeValue( "//ns1:url" );
    log.info("url value: " +  p_url );

    // assign single property
    testRunner.testCase.setPropertyValue( "uploadID", p_url);


    Now, I wanted to port the code to retrieve a list of values (ids) and then perform a testrun on each of them for this xml:

    <Response>
      <e>
          <id>416</id>
          <name>Hans</name>
      </e>
      <e>
          <id>417</id>
          <name>John</name>
      </e>
    </Response>



    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );


    def holder = groovyUtils.getXmlHolder( "getAllTours#ResponseAsXml" );
    def items = holder.getNodeValue( "//ns1:e/id" );
    for(def item: items) {
    log.info("id: " + item );
    }

    As you can see, I even didn't get to the id retrieval part, the problem is that I get: "java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 7 in {//ns1:e/id}: Prefix ns1 has not been declared" Although I just copied the code from the working request above.

    Can you tell me how I can retrieve a list of elements?

    Cheers,

    Jan
  • donaldngo's avatar
    donaldngo
    Occasional Contributor
    Can you declare the namespace in the groovy script as well?

    For example how would I declare ns1?

    groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    holder = groovyUtils.getXmlHolder("create a TSA user#ResponseAsXml");
    context.accountId = holder.getNodeValue( "//ns1:user[1]/accountId[1]");
    context.tenantId = holder.getNodeValue( "//ns1:user[1]/tenantId[1]");
  • Can anybody help me. I'm new to SoapUI and Groovy, I'm using SoapUI 3.6.2Pro version. I'm trying few lines of script in Groovy Script on my SoapUI. It is throwing an error org.mozilla.javascript.EvaluatorException error. The same script is running without any error on my Colleague's machine.

    Here is the script I'm trying

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def requsetHolder = groovyUtils.getXmlHolder( messageExchange.requestContent )
    def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )
    def refNum = responseHolder.getNodeValue("//ns:getScorePricingreasons[1]/ns0:AFXPressResponse[1]/ns0:rewScore[1]")
    assert messageExchange.timeTaken < 2000

    In my SoapUi 'def, assert' are not highlighted into 'Blue'