Web services SoapUI(Groovy)—如果条件为true,则将响应中的节点值传递给另一个请求

Web services SoapUI(Groovy)—如果条件为true,则将响应中的节点值传递给另一个请求,web-services,groovy,soapui,Web Services,Groovy,Soapui,如能提供以下方面的帮助,我将不胜感激: XML响应: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns3:GetSeatPlanAvailabilityResponse xmlns:ns2="http://stagecoach.com/schema

如能提供以下方面的帮助,我将不胜感激:

XML响应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns3:GetSeatPlanAvailabilityResponse xmlns:ns2="http://stagecoach.com/schemas/engine/common" xmlns:ns3="http://stagecoach.com/schemas/engine/seat">
         <ns3:header>
            <ns2:version>1.0</ns2:version>
         </ns3:header>
         <ns3:journeyDetails>
            <ns2:journeyId>4769046</ns2:journeyId>
            <ns2:origin>
               <ns2:cityId>120</ns2:cityId>
               <ns2:description>Memphis, TN</ns2:description>
               <ns2:stop>MEM</ns2:stop>
            </ns2:origin>
            <ns2:destination>
               <ns2:cityId>320</ns2:cityId>
               <ns2:description>Austin, TX</ns2:description>
               <ns2:stop>AUS</ns2:stop>
            </ns2:destination>
            <ns2:departureDate>2014-07-28Z</ns2:departureDate>
            <ns2:departureTime>04:00:00Z</ns2:departureTime>
         </ns3:journeyDetails>
         <ns3:noOfNonReservableSeatsRemaining>70</ns3:noOfNonReservableSeatsRemaining>
         <ns3:singleSeats>
            <ns2:singleSeat>
               <ns2:seatPlanKey>US1</ns2:seatPlanKey>
               <ns2:seatId>7ecc7775-6caa-4e17-80d7-6cfa46be507b</ns2:seatId>
               <ns2:seatNumber>1</ns2:seatNumber>
               <ns2:seatClassCode>FRN</ns2:seatClassCode>
               <ns2:seatDeck>UPPER</ns2:seatDeck>
               <ns2:availableForSelection>true</ns2:availableForSelection>
            </ns2:singleSeat>
            <ns2:singleSeat>
               <ns2:seatPlanKey>US2</ns2:seatPlanKey>
               <ns2:seatId>fe73cc9a-7c4f-4d1f-80e5-6131926af694</ns2:seatId>
               <ns2:seatNumber>2</ns2:seatNumber>
               <ns2:seatClassCode>FRN</ns2:seatClassCode>
               <ns2:seatDeck>UPPER</ns2:seatDeck>
               <ns2:availableForSelection>true</ns2:availableForSelection>
            </ns2:singleSeat>
            <ns2:singleSeat>

               <ns2:seatPlanKey>US3</ns2:seatPlanKey>
               <ns2:seatId>20121517-d657-438f-bc26-92bb98b20bb5</ns2:seatId>
               <ns2:seatNumber>3</ns2:seatNumber>
               <ns2:seatClassCode>FRN</ns2:seatClassCode>
               <ns2:seatDeck>UPPER</ns2:seatDeck>
               <ns2:availableForSelection>true</ns2:availableForSelection>
            </ns2:singleSeat>
            <ns2:singleSeat>
               <ns2:seatPlanKey>US4</ns2:seatPlanKey>
               <ns2:seatId>b93be6b7-ebb9-482e-9ec2-3c9d32beab32</ns2:seatId>
               <ns2:seatNumber>4</ns2:seatNumber>
               <ns2:seatClassCode>FRN</ns2:seatClassCode>
               <ns2:seatDeck>UPPER</ns2:seatDeck>
               <ns2:availableForSelection>true</ns2:availableForSelection>
  </ns2:singleSeat>
         </ns3:singleSeats>
         <ns3:doubleSeats/>
         <ns3:salesClassInformation>
            <ns2:seatClassCode>FRN</ns2:seatClassCode>
            <ns2:salesClassCode>SFRN</ns2:salesClassCode>
            <ns2:salesClassDescription/>
            <ns2:price>3.00</ns2:price>
            <ns2:maxPassengers>1</ns2:maxPassengers>
         </ns3:salesClassInformation>
         <ns3:salesClassInformation>
            <ns2:seatClassCode>LEG</ns2:seatClassCode>
            <ns2:salesClassCode>SLEG</ns2:salesClassCode>
            <ns2:salesClassDescription/>
            <ns2:price>7.00</ns2:price>
            <ns2:maxPassengers>1</ns2:maxPassengers>
         </ns3:salesClassInformation>
         <ns3:salesClassInformation>
            <ns2:seatClassCode>TBL</ns2:seatClassCode>
            <ns2:salesClassCode>STBL</ns2:salesClassCode>
            <ns2:salesClassDescription/>
            <ns2:price>9.00</ns2:price>
            <ns2:maxPassengers>1</ns2:maxPassengers>
         </ns3:salesClassInformation>
      </ns3:GetSeatPlanAvailabilityResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

1
4769046
120
田纳西州孟菲斯
记忆
320
德克萨斯州奥斯汀
澳大利亚
2014-07-28Z
04:00:00Z
70
US1
7ecc7775-6caa-4e17-80d7-6cfa46be507b
1.
FRN
上面的
真的
US2
fe73cc9a-7c4f-4d1f-80e5-6131926af694
2.
FRN
上面的
真的
US3
20121517-d657-438f-bc26-92bb98b20bb5
3.
FRN
上面的
真的
US4
b93be6b7-ebb9-482e-9ec2-3C9D32BEB32
4.
FRN
上面的
真的
FRN
SFRN
3
1.
腿
雪橇
7
1.
TBL
STBL
9
1.

XML请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bas="http://stagecoach.com/schemas/engine/basket" xmlns:com="http://stagecoach.com/schemas/engine/common">
   <soapenv:Header/>
   <soapenv:Body>
      <bas:AddSeatToBasketRequest>
         <bas:header>
            <com:version>1.0</com:version>
            <com:retailOperation>US</com:retailOperation>
            <com:channel>WEB</com:channel>

         </bas:header>
         <bas:basketItemId>56227</bas:basketItemId>
         <!--1 or more repetitions:-->
         <bas:seatSelectionInput>
            <com:passengerOrdinal>1</com:passengerOrdinal>
            <com:SeatId>7ecc7775-6caa-4e17-80d7-6cfa46be507b</com:SeatId>
         </bas:seatSelectionInput>
         <bas:seatSelectionInput>
            <com:passengerOrdinal>2</com:passengerOrdinal>
            <com:SeatId>d653b812-3230-4a31-88e7-a4ad867fb131</com:SeatId>
         </bas:seatSelectionInput>
      </bas:AddSeatToBasketRequest>
   </soapenv:Body>
</soapenv:Envelope>

1
美国
网状物
56227
1.
7ecc7775-6caa-4e17-80d7-6cfa46be507b
2.
d653b812-3230-4a31-88e7-a4ad867fb131
我的要求是,我需要将
传递给另一个请求,首先它应该在
TRUE
时查找条件,否则它应该跳到“FALSE”并选择“并将其传递给请求”


有人能为上述逻辑提供groovy脚本吗?

您需要根据您的具体需要调整以下代码,因为您的问题中仍然缺少信息

// to read a node from your Response
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
// depending on when / how your are doing this, you will need to provide the exact test step name
def xmlHolder = grUtils.getXmlHolder("${context.currentStep.name}#Response")

def seatIdNode = xmlHolder.getDomNode("//*:singleSeat[availableForSelection='true']/seatId")

// if nothing was found
if(seatIdNode == null) {
    testRunner.cancel("seatId was not found!")
    return
}

// you can store this in a testcase property
testRunner.testCase.setPropertyValue("seatId", seatId.firstChild.nodeValue)
// and use it in your next Request as '${#TestCase#seatId}'
有一种方法可以将
seatId
直接写入下一个请求。如果您希望走这条路,我有一个描述如何生成XML请求的示例


最后,所有这些都可以通过纯SoapUI测试步骤完成,而不需要使用Groovy。有条件的转到步骤将检查上面的XPath是否存在,如果不存在,则绕过下一个请求。使用与上面相同的XPath的传输属性步骤将
seatId的值传输到下一个请求。

我编辑了您的帖子,但是,上面的请求和响应都是不完整的XML。另外:1)您是否只需要在Groovy中完成此操作?为什么?当
seatId
false
时,您期望得到什么?谢谢您的回复。我已经编辑了我的文章以包含完整的XML。1) 我更喜欢Groovy,因为我使用的是Soap UI,但我也愿意接受Groovy之外的任何其他可行代码。2) 我的要求是首先查找'True',然后传递seatID,当剩下True时跳到'False',然后传递seatID到请求。谢谢你的要求还不清楚!响应有多个
可用的forselection=true
;你想要哪一个?您的请求有多个
SeatId
;你想要哪一个?我不明白“剩下真时跳到‘假’”;这没有意义。我的请求将有多个SeatID,具体取决于乘客数量,我的要求仅针对1名乘客,即请求将只有1个SeatID。我的要求是当availableForSelection=true时,将响应中的seatID传递给请求中的seatID。如果availableForSelection=true=false,只需忽略并结束。因此,我将手动返回并传递一个不同的journeyID。希望这一点现在清楚了。谢谢你的回复。我编辑了上面的脚本“def xmlHolder=grUtils.getXmlHolder(“GetSeatPlanAvailability#ResponseAsXml”)”,当我运行它时,它返回以下错误xml异常:意外元素:第4行的CDATA错误。TransferProperty工作正常。请尝试使用
def xmlHolder=grUtils.getXmlHolder(“GetSeatPlanAvailability#Response”)
。现在返回另一个错误。“NullPointerException:无法在第5行的null对象错误上获取属性'firstchild'。请尝试此操作。您必须根据您的情况调整XPath,因为我无权访问您的应用程序,因此无法调试它。