2017-08-09 42 views
-1

我想用「groovy」作爲「arg1」「/ arg1」之間的參數將「return」「\ return」之間的標記/主體複製到後續soap請求中腳本。在另一個請求中複製肥皂請求的全部響應作爲參數

我試着參數化每個標籤,但很難這樣做,並想知道是否有任何方法在「return」和「\ return」之間複製整個身體。

不知道我的問題是否有意義,但我是堆棧溢出的新手,並且想要學習soapui和groovy。

我的請求的響應是如下:提前提供任何幫助

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <ns2:getxyz1Response xmlns:ns2="xyz.com"> 
     <return> 
      <xyz1>70</xyz1> 
      <balance>33.0000000000</balance> 
      <carriedBalance>0E-10</carriedBalance> 
      <createDatetime>2017-08-09T00:00:00Z</createDatetime> 
      <createTimeStamp>2017-08-09T22:48:24.423Z</createTimeStamp> 
      <currencyId>1</currencyId> 
      <deleted>0</deleted> 
      <dueDate>2017-08-09T00:00:00Z</dueDate> 
      <id>43194</id> 
      <xyz1>1</xyz1> 
      <xyz1> 
       <amount>10.0000343500</amount> 
       <amountAsDecimal>10.0000343500</amountAsDecimal> 
       <callCounter>0</callCounter> 
       <deleted>0</deleted> 
       <description>testCategory90795 Period from 30/03/2017 to 29/04/2017</description> 
       <id>113492</id> 
       <itemId>220</itemId> 
       <percentage>0</percentage> 
       <price>10.0000343500</price> 
       <priceAsDecimal>10.0000343500</priceAsDecimal> 
       <quantity>1.0000000000</quantity> 
       <quantityAsDecimal>1.0000000000</quantityAsDecimal> 
       <sourcexyz1Id>22143</sourcexyz1Id> 
      </xyz1> 
      <xyz1> 
       <amount>10.0000343500</amount> 
       <amountAsDecimal>10.0000343500</amountAsDecimal> 
       <callCounter>0</callCounter> 
       <deleted>0</deleted> 
       <description>testCategory90795 Period from 30/04/2017 to 29/05/2017</description> 
       <id>113493</id> 
       <itemId>220</itemId> 
       <percentage>0</percentage> 
       <price>10.0000343500</price> 
       <priceAsDecimal>10.0000343500</priceAsDecimal> 
       <quantity>1.0000000000</quantity> 
       <quantityAsDecimal>1.0000000000</quantityAsDecimal> 
       <sourcexyz1Id>22143</sourcexyz1Id> 
      </xyz1> 
      <xyz1> 
       <amount>10.0000343500</amount> 
       <amountAsDecimal>10.0000343500</amountAsDecimal> 
       <callCounter>0</callCounter> 
       <deleted>0</deleted> 
       <description>testCategory90795 Period from 30/05/2017 to 29/06/2017</description> 
       <id>113494</id> 
       <itemId>220</itemId> 
       <percentage>0</percentage> 
       <price>10.0000343500</price> 
       <priceAsDecimal>10.0000343500</priceAsDecimal> 
       <quantity>1.0000000000</quantity> 
       <quantityAsDecimal>1.0000000000</quantityAsDecimal> 
       <sourcexyz1Id>22143</sourcexyz1Id> 
      </xyz1> 
      <xyz1> 
       <amount>3.0000103050</amount> 
       <amountAsDecimal>3.0000103050</amountAsDecimal> 
       <callCounter>0</callCounter> 
       <deleted>0</deleted> 
       <description>GST</description> 
       <id>113495</id> 
       <itemId>45</itemId> 
       <percentage>0</percentage> 
       <price>10.0000000000</price> 
       <priceAsDecimal>10.0000000000</priceAsDecimal> 
       <quantity>1.0000000000</quantity> 
       <quantityAsDecimal>1.0000000000</quantityAsDecimal> 
       <sourcexyz1Id>22143</sourcexyz1Id> 
      </xyz1> 
      <isReview>0</isReview> 
      <number>40677</number> 
      <orders>44652</orders> 
      <xyz1Attempts>0</xyz1Attempts> 
      <statusDescr>Unpaid</statusDescr> 
      <statusId>2</statusId> 
      <toProcess>1</toProcess> 
      <total>33.0000000000</total> 
      <xyz1Id>22143</xyz1Id> 
     </return> 
     </ns2:getxyz1Response> 
    </soap:Body> 
</soap:Envelope> 

感謝。

回答

0

1 /您需要從源testStep(在下例中命名爲「SOAP Request」)中檢索XML並將其作爲「返回」節點的目標。

def sourceTCresponse = context.expand('${SOAP Request#Response}') 
def sourceTCresponse_XML = new XmlParser().parseText(sourceTCresponse) 
def targetNode = sourceTCresponse_XML.'**'.find {it.name() == 'return'} 

2 /你需要從你的目標一步步測試(下面的例子在一個名爲 'SOAP請求2')來檢索XML

def targetTestStep = testRunner.testCase.testSteps["SOAP Request2"] 
def targetTestStep_Request = targetTestStep.getPropertyValue("Request") 
def targetTC_XML = new XmlParser().parseText(targetTestStep_Request) 

3 /於是,節點追加1 /從2 ARG1節點/

targetTC_XML.'**'.find {it.name() == 'arg1'}.append(targetNode) 

4 /那麼最終的XML轉換爲字符串

def xmlOutput = new StringWriter() 
def xmlNodePrinter = new XmlNodePrinter(new PrintWriter(xmlOutput)) 
xmlNodePrinter.print(targetTC_XML) 
String finalXML_asString = xmlOutput.toString() 

5 /然後將此字符串寫入您的目標測試步驟

targetTestStep.setPropertyValue("Request", finalXML_asString)`