Forum Discussion

SOAish's avatar
SOAish
New Contributor
12 years ago

Adding HTTP Header for a Soap Request

I have many Test Suites (around 60) with Test Cases. I have to add Additional Http Header ("Header, value" pair)for each Request in all the Test Cases. I can use global Property as I have to pass the same header value accross all the SOAP requests; But can I get any other way either through groovy / some other feature in SOAPUI?

1 Reply

  • biju74's avatar
    biju74
    New Contributor
    Add a groovy step with following code

    import com.eviware.soapui.impl.wsdl.teststeps.*
    import com.eviware.soapui.support.types.StringToStringMap

    def testSuite = testRunner.testCase.testSuite

    def accessToken = "MyToken"
    def headers = new StringToStringMap()
    headers.put("Authorization","Bearer " + accessToken)

    testSuite.testCaseList.each { testCase ->
    log.info("Setting ${testCase.name}")
    testCase.testStepList.each { testStep ->
    log.info("Setting ${testStep.name}")
    if(testStep instanceof RestTestRequestStep ) {
    log.info("Setting HTTP headers ${headers} in test case ${testStep.name}")
    testStep.testRequest.setRequestHeaders( headers)
    }
    }
    }