Soap UI广告和一个要请求的节点(Groovy) [英] Soap UI ad an Node to Request (Groovy)
问题描述
我遇到了问题.
所以我得到了这样的WSDL:
So i got an WSDL like this:
<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可以具有一个或多个表述,这取决于数据库.现在我的问题是-如何解决这个问题才能使重复变得动态.
for Testing via SoapUI, the Problem is now, that the subnode5 can have one ore more reptions, it depends from the Database. Now my questions - how can isolved this to make the repetitions dynamic.
所以我尝试通过这样的常规脚本附加subnode5:
so i try t append the subnode5 via a groovy script like this:
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()
但是我收到一个错误消息:
but i get an errormessage:
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"?>,...]可能的解决方案:第29行的appendChild(org.w3c.dom.Node)错误
groovy.lang.MissingMethodException: No signature of method: org.apache.xmlbeans.impl.store.Xobj$ElementXobj.appendChild() is applicable for argument types: (org.apache.xmlbeans.impl.store.Xobj$ElementXobj, java.lang.Boolean) values: [?xml version="1.0" encoding="UTF-8"?> , ...] Possible solutions: appendChild(org.w3c.dom.Node) error at line: 29
我将为请求添加一个新孩子
what i will is added a new child to the request
<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>
推荐答案
这是一个路线图-您需要对其进行调整以适合您的特定需求!
Here is a roadmap - you will need to adjust it to suit your particular needs!
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)
这里有一些其他阅读内容(如果有兴趣).
Here is some additional reading, if interested.
这篇关于Soap UI广告和一个要请求的节点(Groovy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!