问题
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:
- Create a new property in your test case, called ValuesXML
- Add a step with your original request, the source data
- Create a property transfer step
- Add a new transfer
- Select source as the xml from your response
- Check the "use XQuery" checkbox
- Select target as the property ValuesXML
- Add the code below to the source window
- Add a step with the target request, where you want your modified data
- In the XML request, where the clause should be, put ${#TestCase#ValuesXML}
- 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