Forum Discussion

rka's avatar
Occasional Contributor
9 years ago

Maintain HTTP Session: Should pass cookies to following request

Hi, I was reading this community forum for a long time about maintaining https session over several requests. But I'm not able to run it sucessfully.   I'm on Ready!API 1.5.0  (SoapUI NG Pro) Buil...
  • JustinM89's avatar
    9 years ago

    In your REST request, you should add those 3 header fields (you don't need to supply a value):



    Then in the actual test step, double click the value field of each, right-click, then use 'Get Data' to get each header from the response of a previous request:


  • rka's avatar
    9 years ago

    Hi Justin

    Thanks for that hint.

    But it doesn't work in my case.


    a) my first request contains in it's response:

    Set-Cookie: JSESSIONID=xxxxxxxxxxxx; Path=/yyyyyyyyyyyyyyyy; Secure
    Set-Cookie: WAF-XSRF-TOKEN=zzzzzzzzzzzzzzzz; Path=/
    Set-Cookie: XSRF-TOKEN=aaaaaaaaaaaaaaaaa; Path=/
    Access-Control-Allow-Headers: origin, content-type, accept, X-XSRF-TOKEN


    b) I have to transfer those cookies to the next request


    Now I try with a groovy script

    Actually I think it would work, but it douplicates all cookies in the header, each time I start the script ??


    def header = testRunner.testCase.getTestStepByName("firstLoginCookie").httpRequest.response.responseHeaders["Set-Cookie"]
     header=header.toString()" Current XSRF-TOKEN header: " + header)
     start=header.indexOf(" XSRF-TOKEN=")" Current XSRF-TOKEN start: " + start+1)

     end=header.indexOf("; Path=/]")" Current XSRF-TOKENend: " + end)

     testCaseProperty= header.substring(start+1,end)
     vXsrf=testCaseProperty"Current xsrf: " + vXsrf) 

    ////////////////" Current WAF-XSRF-TOKEN header: " + header)
     start=header.indexOf(" WAF-XSRF-TOKEN=")" Current WAF-XSRF-TOKEN start: " + start+1)

     end=header.indexOf("; Path=/, ")" Current WAF-XSRF-TOKEN end: " + end)

     testCaseProperty= header.substring(start+1,end)
     vWafXsrf=testCaseProperty"Current wafxsrf: " + vWafXsrf) 

    ////////////////" Current JSESSIONID header: " + header)
     start=header.indexOf("JSESSIONID=")" Current JSESSIONID start: " + start)

     end=header.indexOf("; Path=/com.avaloq")" Current JSESSIONID end: " + end)

     testCaseProperty= header.substring(start,end)
     vJsessionId=testCaseProperty"Current vJsessionId: " + vJsessionId) 

    // Iterate through all test steps and add the session cookie to the headers.
    for ( tstep in context.testCase.testSteps ) {
     testStepName = ( tstep.key )"Current testStepName: " + testStepName);

     if ( testStepName != 'firstLoginCookie' && testStepName != 'SetXSRFheadersForAll') {"Cookie set for " + testStepName)
     def headers=testRunner.testCase.testSteps[testStepName].testRequest.requestHeaders 
     headers.put('Cookie', vXsrf) 
     headers.put('Cookie', vWafXsrf)
     headers.put('Cookie', vJsessionId +'; Path=/; Secure')




    Regards, Reto