Pulling details from response to new request SoapUI

跟風遠走 提交于 2019-12-24 00:56:35

问题


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.


回答1:


  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. GO!

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.



来源:https://stackoverflow.com/questions/9637167/pulling-details-from-response-to-new-request-soapui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!