0
votes

I am trying to do the following in SOAPUI:

  1. Read a response and extract a node from it
  2. Insert the node into another request
  3. Generate some xml in a Groovy script and store in a TestCase property
  4. Insert the generated xml from the property as a child node to the node inserted in Step 2.

For 1 and 2: The structure of the response is something like

<A><B>bb</B><C>cc</C><D>dd</D></A>

I extract it via a Property Transfer step using //A to identify the beginning of the node, and passing the node with its children to the request in the next test step. Until this, the node in the request has no content. This works.

For 3 I generate something like

<E>ee</E>

The goal after step 4 is a request structure looking like this:

 <A><E>ee</E><B>bb</B><C>cc</C><D>dd</D></A>

A solution using

${#TestCase#new_xml}

to insert the node does not work because there is no way to place the property where the E node should be (as far as I know).

I tried inserting the E node via another Property Transfer test step - the value of the property gets inserted in the request as child to the A node (same way the A node was copied from the response to the next request in Step 2). The result is this:

<A><![CDATA[<E>ee</E>]]<<B>bb</B><C>cc</C><D>dd</D></A>

I would like to know:

  1. How to insert the E node as a child node to the A node while avoiding CDATA (or removing the CDATA subsequently).

  2. Why the xml is passed without CDATA in Step 2 which also uses the SOAPUI Property Transfer Step, but not in Step 4.

Any tips appreciated!

1
Your question is rather broad, so my answer below is equally as broad. If you want to narrow things down, have a read through How to Ask and edit your question. - SiKing

1 Answers

2
votes

For 1 & 2, you can use just a simple property expansion.

Let say your Response looks like:

<AAA>
    <BBB/>
    <CCC/>
    <BBB/>
    <BBB/>
    <DDD>
        <BBB/>
    </DDD>
    <CCC/>
</AAA>

And let say you want to transfer the entire node DDD, including the children. In your next request you would use ${<TestStep_name>#Response//*:DDD}. Note the *: means "any namespace", since in a real SOAP Response you will probably have some kind of namespace.

For 3:

// Generate some xml in a Groovy script
def xml = '<AAA><BBB/><CCC/><BBB/><BBB/><DDD><BBB/></DDD><CCC/></AAA>'
// store in a TestCase property
testRunner.testCase.setPropertyValue('my_property', xml)

If you want to get more fancy, you could use one of the many Java XML libraries, some of which are packaged with SoapUI. Here is one possibility.

For 4, you would again use property expansion: ${#TestCase#my_property}