Forum Discussion

faisalmalik's avatar
faisalmalik
New Contributor
6 years ago

Pass cookie value in READY API from response to another test step

Hi,

 

I have a test case which generates a cookie in the response headers in one of the test steps. The cookie needs to be persisted in the rest of the tests. I have tried using the option Maintain Http Session and that doesn't work. 

 

Can you please let me know how to pass that cookie which is only in the headers and the raw response.

Is there a  Groovy script that needs to be written for this or it can be passed using the headers itself.

 

As of now, I am passing a hardcoded value for the cookie which works for the flow we have.

However, that makes the tests brittle. If someone could help with the groovy script that would be helpful.

 

Also, I have no knowledge of groovy.

 

Thanks 

Faisal 

5 Replies

  • richie's avatar
    richie
    Community Hero
    hi,

    if youre after a script to extract header values to pass onto subsequent steps Bill_In_Irvine gave me a script that enables this i believe. im not at my desk now, but will respond in a couple of hours with Bill's script.

    cheers,

    richie
  • nmrao's avatar
    nmrao
    Champion Level 3
    That is very much possible.

    Here is the approach:
    Have a script assertion for the step where you get the cookie and extract the cookie and store it at project level or so.

    Then use the Events feature, to add the cookie for each outgoing requests.
    • richie's avatar
      richie
      Community Hero

      faisalmalik

       

      nmrao knows way more than I do about this stuff so I'd listen to him.

       

      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])

      Cheers,

       

      richie

       

      • faisalmalik's avatar
        faisalmalik
        New Contributor

        Thanks Guys, 

         

        Sorry for the delayed response, as I have been on a parental Leave :)  I have tried richie 's method and worked like a charm. 

        didn't  get the time to try out nmrao  method. 

         

        Cheers 

        Faisal