Forum Discussion

NarasimhaRaoSL's avatar
NarasimhaRaoSL
New Contributor
7 years ago
Solved

Retrieving a cookie from response header using Groovy

Could you help me how to retrieve a cookie from response header using Groovy?

  • Try something like this 

     

    def cookie_name = testRunner.testCase.testSteps["Request_Step_Name"].testRequest.response.responseHeaders["Cookie-Name"]

    log.info cookie_name

     

    // Change Cookie-Name to whatever the name of the header name you are looking for

3 Replies

  • Try something like this 

     

    def cookie_name = testRunner.testCase.testSteps["Request_Step_Name"].testRequest.response.responseHeaders["Cookie-Name"]

    log.info cookie_name

     

    // Change Cookie-Name to whatever the name of the header name you are looking for

    • NarasimhaRaoSL's avatar
      NarasimhaRaoSL
      New Contributor

      Hi, Tried the above code but getting NULL as result. Its a browser generating cookie. So can we get browser generating cookie using groovy?

      • ebbydurai's avatar
        ebbydurai
        Senior Member

        bagochip's example should work for you if you correctly replace

        "Request_Step_Name" with your test step and "Cookie-Name" with the correct response header name in which you are getting the cookie value