我想使用groovy脚本将“return”“\ return”之间的标签/正文复制到后续的soap请求中,作为“arg1”“/ arg1”之间的参数。
我试图对每个标签进行参数化,但很难这样做,并想知道是否有任何方法可以在“return”和“\ return”之间复制整个主体。
不确定我的问题是否有意义,但我是Stack-overflow的新手,想学习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 :(得分:0)
1 /您需要从源testStep检索XML(在下面的示例中命名为'SOAP Request')并定位'return'节点。
def targetTestStep = testRunner.testCase.testSteps["SOAP Request2"]
def targetTestStep_Request = targetTestStep.getPropertyValue("Request")
def targetTC_XML = new XmlParser().parseText(targetTestStep_Request)
2 /您需要从目标testStep检索XML(在下面的示例中命名为'SOAP Request2')
targetTC_XML.'**'.find {it.name() == 'arg1'}.append(targetNode)
3 /然后将节点从1 /追加到2 /
的arg1节点def xmlOutput = new StringWriter()
def xmlNodePrinter = new XmlNodePrinter(new PrintWriter(xmlOutput))
xmlNodePrinter.print(targetTC_XML)
String finalXML_asString = xmlOutput.toString()
4 /然后将最终XML转换为字符串
targetTestStep.setPropertyValue("Request", finalXML_asString)`
5 /然后将此字符串写入目标测试步骤
{{1}}