Forum Discussion

SK07's avatar
SK07
Contributor
6 years ago

Pass header values to test steps

I want to pass the header values to each test steps like below
using groovy script. Any help is appreciated.
Test step 1 : Header1, value; Header2, value
Test step 2:  Header1, value; Header2, value

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    There are multiple ways:
    1. If the headers are fixed, define them at request level. In this approach, no scripting required.
    2. The headers can be automatically added using Events feature. But, if the headers are not intended for all the requests, then it prefer #1. And this requires script.
    • SK07's avatar
      SK07
      Contributor

      Thanks nmrao. The token is not fixed. I have to generate the token and then if I can pass the token thru script 

      to all the test steps and then I can execute the test suite instead manually passing for each test step.

      Is that possible using script....

      • richie's avatar
        richie
        Community Hero

        SK07

         

        I don't know if I may be misunderstanding you or not - so I might not be helping at all here.

         

        Are you talking about passing a header value from a request's response to subsequent test steps?  If this is the case then the following might help (unless I misunderstand).

         

        @Bill_In_Irvine gave me the following to extract a header value and pass it to a Properties step (so cred goes to Bill for this - not me)

         

        //Takes one of the elements of the response Header
        def value = testRunner.testCase.testSteps["REST request step name"].testRequest.response.responseHeaders["headername"]
        
        //Read this value into a parameter
        def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
        groovyUtils.setPropertyValue("Properties", "headername",value[0])

        I then just added in a header parameter on each of the requests and sourced the value from the Properties file.

         

        I hope this helps, but I'm not clear exactly about what you are asking,

         

        cheers,

         

        richie