【问题标题】:Soap UI ad an Node to Request (Groovy)Soapui 添加一个节点到请求(Groovy)
【发布时间】:2015-03-19 15:25:26
【问题描述】:

我遇到了问题。

所以我得到了这样的 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 进行的测试,现在的问题是,subnode5 可以有一个或多个 reptions,这取决于数据库。现在我的问题 - 如何解决这个问题以使重复动态化。

所以我尝试通过这样的 groovy 脚本附加 subnode5:

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.xmlbeans.impl.store.Xobj$ ElementXobj, 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> 

【问题讨论】:

    标签: groovy soapui appendchild


    【解决方案1】:

    这是一个路线图 - 您需要对其进行调整以满足您的特定需求!

    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)
    

    这里有一些additional reading,如果有兴趣。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多