Forum Discussion

anand7892's avatar
Occasional Contributor
7 years ago

Adding a request Header in all rest request in different Suites

I want to add a header in all the rest Request in my project The value that i need to put in the header is getting generated by login API.   I am using Pro Version Can you suggest me steps to fol...
  • anand7892's avatar
    7 years ago


    You could have given me more precise solution to save my time but seems like you are here to refer to only urls of SOAPUI


    So i wasted my few hours and find a better solution:


    Here is more precise solution to this:

    Problem: I wanted to add a header with name "Authorization" and value "${#project#token}"(stored at project level)'



    Run Groovy script and it will solve your problem.



    import com.eviware.soapui.impl.wsdl.teststeps.*
    def project = context.testCase.testSuite.project
    def token = "\${"+"#"+"Project"+"#"+"token}"
    def valueOf = { key -> testSuite.getPropertyValue( key ) }
    project.testSuiteList.each{ testSuite ->
    testSuite.testCaseList.each { testCase ->
       testCase.testStepList.each { testStep ->
          if( testStep instanceof WsdlTestRequestStep || testStep instanceof RestTestRequestStep  ) 
          	def headers = new StringToStringMap()
   "Setting HTTP headers ${headers} in test case ${testCase.label}")