因此,我想做的是将SOAP标头自动添加到SoapUI中生成的每个请求中,因为我有成百上千个请求,而手动执行此操作很烦人。
可以说这是我从WSDL生成的示例请求,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pol="http://something">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<pol:GetSomething>
<tag1>3504</tag1>
<tag2>ALL</tag2>
</pol:GetSomething>
</soapenv:Body>
</soapenv:Envelope>
当我发出请求时,我希望SoapUI对其进行修改以使其看起来像这样:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pol="http://something">
<soapenv:Header>
<token xmlns="ns1">${TOKEN}</token>
<user xmlns="ns2">user</user>
<system xmlns="ns3">system</system>
</soapenv:Header>
<soapenv:Body>
<pol:GetSomething>
<tag1>3504</tag1>
<tag2>ALL</tag2>
</pol:GetSomething>
</soapenv:Body>
</soapenv:Envelope>
在SoapUI中可以吗?
在您的testCase中,您可以添加Groovy Script类型的第一步,在此脚本中,您可以操纵每个请求以在上添加必要的元素<soap:Header>
,我给您一个适合我的示例:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def tcase = testRunner.testCase ;
// get total number of testSteps
def countTestSteps = tcase.getTestStepList().size();
// start with 1 to avoid groovy script testStep
for(i=1;i<countTestSteps;i++){
// get testStep
def testStep = tcase.getTestStepAt(i);
// get request
def request = testStep.getProperty('Request').getValue();
// get XML
def xmlReq = groovyUtils.getXmlHolder(request);
// get SOAPHEADER
def soapHeader = xmlReq.getDomNode("declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/'; //soap:Header")
// document to create new elements
def requestDoc = soapHeader.getOwnerDocument()
// create new element
def newElem = requestDoc.createElementNS(null, "element");
// insert in header
soapHeader.insertBefore(newElem, soapHeader.getFirstChild());
// now put your new request in testStep
log.info xmlReq.getXml();
testStep.setPropertyValue('Request', xmlReq.getXml());
}
此示例代码仅在上添加了一个新元素<soap:header>
,但您可以对其进行修改以添加属性,文本内容和更多节点。您还可以看一下:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句