Extrayendo detalles de la respuesta a la nueva solicitud SoapUI

I'm using SoapUI 3.6.1. I need to pull details from response and insert them to next request. I try to do this by'Property Transfering'. In first request I'm getting some details and in the response I can see 'Sections'. This 'section' can contain many 'Controls' and every 'Control' has some values. My response i'm getting:

                ...
              <a:Section>
                 <a:Controls>
                    <a:Control>
                       <a:Code>11</a:Code>
                       <a:Id>11</a:Id>
                       <a:Label>bkBranded</a:Label>
                       <a:Mandatory>true</a:Mandatory>
                       <a:SortOrder>223</a:SortOrder>
                       <a:Type>RadioButton</a:Type>
                       <a:Values>
                          <a:Value>
                             <a:Code>bkBrandedWindow</a:Code>
                             <a:SortOrder>1</a:SortOrder>
                             <a:Value>Yes</a:Value>
                          </a:Value>
                          <a:Value>
                             <a:Code>bkBrandedWindow</a:Code>
                             <a:SortOrder>2</a:SortOrder>
                             <a:Value>No</a:Value>
                          </a:Value>
                       </a:Values>
                    </a:Control>
                     ...

The main conditions are to get only 'Controls' which are mandatory (true) and only one of available 'Values'. Details I need to get in next request is like these:

  ... 
 <Values>
<Value>
    <ControlCode>8003</ControlCode>
    <Id>8003</Id>
    <Value>123</Value>
    <ValueCode>bkBranded</ValueCode>
</Value>
    <Value>
    <ControlCode>455</ControlCode>
    <Id>455</Id>
    <Value>1/2</Value>
    <ValueCode>bkOther</ValueCode>
</Value>
....

It means i need 'Code' , 'Id', 'Value' , 'Value code' from response. Maybe there is the possibility to use 'If..Else' statement or smth else. Thanks in advance.

preguntado el 09 de marzo de 12 a las 16:03

1 Respuestas

  1. Create a new property in your test case, called ValuesXML
  2. Add a step with your original request, the source data
  3. Create a property transfer step
  4. Add a new transfer
  5. Select source as the xml from your response
  6. Check the "use XQuery" checkbox
  7. Select target as the property ValuesXML
  8. Add the code below to the source window
  9. Add a step with the target request, where you want your modified data
  10. In the XML request, where the clause should be, put ${#TestCase#ValuesXML}
  11. ¡IR!

The code, that should go in the "source" of the property transfer

<Values>
{
    for $z in //Control
    where $z/Mandatory eq "true"    
    return 
        <Value>
            <ControlCode>{data($z/Code/text())}</ControlCode>
            <Id>{data($z/Id/text())}</Id>
            <Value>     
            {
                let $values :=
                for $x in //Value          
                order by $x/SortOrder
                return $x/Value 

            return $values[1]
            }
            </Value>
        <ValueCode>{data($z/Label/text())}</ValueCode>
       </Value>
}
</Values>

NOTE: You might have to add an "a:" in front of the tag names in the XQuery expression, to read your source data correctly. That will also require you to declare the "a" namespace, which is easily done with the "declare" button.

respondido 21 mar '12, 15:03

I assumed you wanted the lowest sort order value first. It required quite a bit of XQuery, which is not my area of expertise... Also, I am using the Pro version 4.5, so let me know if you have problems with it in SoapUI. - Por Åkerberg

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.