【问题标题】:SoapUI - Automatically add custom SOAP headers to outgoing requestSoapUI - 自动将自定义 SOAP 标头添加到传出请求
【发布时间】:2014-01-22 08:42:01
【问题描述】:

所以我想做的是自动将 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 中可以吗?

【问题讨论】:

    标签: soap wsdl soapui


    【解决方案1】:

    在您的测试用例中,您可以添加 Groovy 脚本类型的第一步,在此脚本中,您可以操纵每个请求以在 &lt;soap:Header&gt; 上添加必要的元素,我给您一个适合我的示例:

    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());
    }
    

    此示例代码仅在&lt;soap:header&gt; 上添加了一个新元素,但您可以对其进行修改以添加属性、文本内容和更多节点。你也可以看看:

    dynamically create elements in a SoapUI request | SiKing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-14
      • 2023-03-25
      • 2013-11-13
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      相关资源
      最近更新 更多