Forum Discussion

Rincewind's avatar
Rincewind
Regular Visitor
6 years ago

How i tranfer a cookie from a response (raw) in a next step and send it there

Hello,

I am beginning to work with SoapUI and so my level is not high and so a have a question..

I have a Rest-Service and i must login on a website and get in the response a cookie.

For the next steps i must use and send this cookie on a other website to be able to test on this site the api.

So, now my question. How can i transfer this cookie in the next step and send it?


Thanks.

 

Best Regards

Uwe

3 Replies

  • richie's avatar
    richie
    Community Hero

    Hi,

     

    If I understand correctly - this seems fairly straight forward - if I'm getting the gist

     

    the cookie's in the response headers - right?  There's a bit of groovyscript one of the other lads on the forum gave me to do this.

     

    Essentially  you need to perform a property transfer, grabbing the cookie's value writing it either directly to the subsequent request or a Properties step.  I did the same thing on a test case and it had the following steps

     

    1st REST request step (generates the cookie)

    Groovy step

    Properties step

    2nd REST request step

     

    The code to grab the cookie's value from the 1st REST step headers and save it to the Properties step is as follows:

     

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

    If I understand what you need - this will do it - if I don't then I've wasted your time reading this and mine typing this out! :)

     

    Cheers!

     

    richie

    • Lucian's avatar
      Lucian
      Community Hero

      Just right click on the test case -> settings -> maintain http session. This should do it...

      • Olga_T's avatar
        Olga_T
        SmartBear Alumni (Retired)

        Hi all,

         

        Thanks a lot, Community Leaders!

         

        Rincewind, did the above suggestions help you?
        If your question was answered, can you please mark the reply that helped you as a Solution so that other users could find it easily in the future?

        Thanks in advance,