Soap UI广告一个节点请求(Groovy)



我遇到了一个问题。

所以我得到了这样一个WSDL:

     <node1>
        <subnode1>data</subnode1>
        <subnode2>data</subnode2>
        <subnode3>data</subnode3>
        <subnode4>data</subnode4>
        <!--Zero or more repetitions:-->
        <subnode5>
           <subsubnode1>data</subsubnode1>
           <subsubnode2>data</subsubnode2>
           <subsubnode3>data</subsubnode3>
        </subenode5>
     </node1> 

对于通过SoapUI进行测试,现在的问题是,子节点5可以有一个或多个报告,这取决于数据库。现在我的问题是——如何将其隔离开来,使重复充满活力。

因此,我尝试通过如下groovy脚本附加子节点5:

import com.eviware.soapui.support.XmlHolder;
import com.eviware.soapui.support.GroovyUtils;
def groovyUtil = new GroovyUtils( context )
def holder = groovyUtil.getXmlHolder( "name#Request" )
def parentnode  = holder.getDomNode( "//node1" )
def text    = '''
            <subnode5>
             <subsubnode1>data</subsubnode1>
             <subsubnode2>data</subsubnode2>
             <subsubnode3>data</subsubnode3>
            </subnode5>
           '''.stripMargin()
 def nodetext = groovyUtil.getXMLHolder( text )
 def nodeItem = nodetext.getDomNode ( "//subnode5")
 parentnode.appendChild(nodeItem, true)
 holder.updateProperty()

但我收到一条错误消息:

groovy.lang.MissingMethodException:方法没有签名:org.apache.xmlbeans.impl.store.Xobj$ElementXobj.appendChild()适用于参数类型:(org.apache.xxmlbeans.imp.store.Xobj$ElementXtobj,java.lang.Boolean)值:[?xml version="1.0"encoding="UTF-8"?>,…]可能的解决方案:appendChild(org.w3c.dom.Node)第29行错误

我将在请求中添加一个新的子项

  <node1>
    <subnode1>data</subnode1>
    <subnode2>data</subnode2>
    <subnode3>data</subnode3>
    <subnode4>data</subnode4>
    <subnode5>
       <subsubnode1>data</subsubnode1>
       <subsubnode2>data</subsubnode2>
       <subsubnode3>data</subsubnode3>
    </subenode5>
    --first repition--
    <subnode5>
       <subsubnode1>data</subsubnode1>
       <subsubnode2>data</subsubnode2>
       <subsubnode3>data</subsubnode3>
    </subenode5>
   --second repition--
    <subnode5>
       <subsubnode1>data</subsubnode1>
       <subsubnode2>data</subsubnode2>
       <subsubnode3>data</subsubnode3>
    </subenode5>
    .... and so on 
 </node1> 

这里有一个路线图-您需要调整它以满足您的特定需求!

import com.eviware.soapui.support.GroovyUtils
// create groovyUtils and XmlHolder for request
def grUtils = new GroovyUtils(context)
def requestHolder = grUtils.getXmlHolder("name#Request")
// find the Node that I am interested in
def requestNode = requestHolder.getDomNode("//*:node1")
// the Document object is used to create new nodes
def requestDoc = requestNode.getOwnerDocument()
// create the whole structure 3 times
3.times {
    // create a new Element in the Document
    def subelement5 = requestDoc.createElement("subnode5")
    def subnode5 = requestNode.insertBefore(subelement5, requestNode.getFirstChild())
    // create the sub-sub nodes
    1..3.each {
        def subsubelement = requestDoc.createElement("subsubnode${it}")
        subnode5.insertBefore(subsubelement, subnode5.getFirstChild())
        // add in the data text
        subsubelement.appendChild(requestDoc.createTextNode("data"))
    }
}
// write the Document out to the request
requestHolder.updateProperty(true)

如果感兴趣的话,这里还有一些补充阅读。

最新更新