Forum Discussion

enliven's avatar
enliven
Contributor
16 years ago

Modify soap:header when adding TestSteps via WsdlTestRequestStepFactory

I am currently populating test-steps dynamically. Now, I need to modify the default/generated request before saving to the testcase.

How can I modify (or replace) some information in the Header to include text for property expansion either before or after the call to WsdlTestRequestStepFactory.createConfig(wsdlOperation, name)?

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    You are creating test steps with associated operations. When test step is run associated operation, or to be more precise request(s) in that operation is called. So, basically you could iterate trough all requests in operation, get their headers and modify them.
    Use WsdlOperation.getRequestAt() or WsdlOperation.getRequestByName() to get request and than WsdlRequest.getRequestHeaders() and to set them WsdlRequest.setRequestHeaders().

    Hope this helps, let me know.

    robert
  • Sorry, I should have been more explicit. I am trying to perform the SoapRequest Header change during creation of new TestRequests from New or Existing project requests. When I access the wsdlTestCase.addTestStep(testStepConfig).wsdlTestRequestStep.getTestRequest().getReqeustHeaders() they are empty, but the generated TestStepRequests have full soapEnv with Default or Existing custom header intact (which is what I need to replace).

    suggestions?
  • I was able to resolve using the following to replace the current generated custom soap header with one populated by from DataGen. Im not able to generate test cases with much of the common testing stuff I need, now for the rest

    def holder = groovyUtils.getXmlHolder(currentRequest.getRequestContent())
    def xmlUtils = new com.eviware.soapui.support.xml.XmlUtils();
    def dNode = holder.getDomNode("//ns:RequestHeader")
    holder.removeDomNodes(xmlUtils.createXPath(dNode))
    holder["//soapenv:Header"] = RequestHeaderExpansion
    wsdlTestRequestStep.getTestRequest().setRequestContent(holder.xml)


    which will change:
       <soapenv:Header>
          <ns:RequestHeader>
            <ns:CompanyCode>xxx</ns:CompanyCode>
             <ns:UserName>xxx</ns:UserName>
             <ns:Password>xxx</ns:Password>
             <ns:DataStoreName>xxx</ns:DataStoreName>
             <ns:RequestId>xxx</ns:RequestId>
          </ns:RequestHeader>
       </soapenv:Header>


    to:
    <soapenv:Header>
         ${=context.testCase.testSuite.project.testSuites["TestSuite-Project"].getTestCaseByName("ConnectionProperties").getTestStepByName("DataGen").getPropertyValue("RequestHeader")}
    </soapenv:Header>