Forum Discussion

EmBer's avatar
EmBer
New Contributor
12 years ago

Adding headers using a script

Hi, many of my testSteps require the same Header. I've been adding it manually on the teststep's view under the header tab.
I'd like to do this programatically through a groovy script, but I'm not sure how. Suggestions?

3 Replies

  • Hi EmBer,

    Please use the below code which changes the header property across all testsuite(including all testcase and teststep)


    testSuiteList = project.getTestSuites()
    testSuiteList.each{
    testSuite = project.getTestSuiteByName(it.key)
    testCaseList = testSuite.getTestCases()
    log.info "TestSuite :: $testSuite.name"
    testCaseList.each{
    testCase = testSuite.getTestCaseByName(it.key)
    wsdlTestSteps = testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class ) //only WsdlTestRequest steps
    wsdlTestSteps.each{
    it.properties['headerproperty1'].value = "headerproperty1 value")
    it.properties['headerproperty2'].value = "headerproperty 2 value")
    }
    }
    }

  • EmBer's avatar
    EmBer
    New Contributor
    I trimmed your code down since I only want to set the header for all the steps in a testcase. I don't see the headerproperty1 or 2 in my headers after running the script. Is there another way to do this? Your original script also didn't work because it has some syntax errors



    wsdlTestSteps = testRunner.getTestCase().getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class ) //only WsdlTestRequest steps
    wsdlTestSteps.each{
    log.info(it)
    it.properties['headerproperty1'].value = ("headerproperty1 value")
    it.properties['headerproperty2'].value = ("headerproperty 2 value")
    }
  • Hi,

    Try the below code.


    def testStep = context.testCase.getTestStepList()
    testStep.each{

    if ((it.config.type)=='request'){
    def stepRequestName = it.name
    def tp = new com.eviware.soapui.support.GroovyUtils( context )
    tp.setPropertyValue(stepRequestName,'header key', 'header value')
    }
    }