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) Build Date: 20151106-1037
All I want to do is
1.) Request A contains in its response 3 cookies (within the http header)
2.) I would like to have this 3 cookies transfered in Request B (also in the http header)
It's as simple, but it doesn't work.
I tried: to pass the cookie around, go to the testcase options and turn on "maintain HTTP session".
Simply enable this option to true does not work
I also tried to use a property transfer, but how can I easily pass all cookies?
I don't want to write groovie code. I think such basic requirement should be handled by the tool itself.
Maybe someone has an idea?
Thanks
Regards, Reto
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:
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-TOKENb) 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()log.info(" Current XSRF-TOKEN header: " + header)
start=header.indexOf(" XSRF-TOKEN=")
log.info(" Current XSRF-TOKEN start: " + start+1)end=header.indexOf("; Path=/]")
log.info(" Current XSRF-TOKENend: " + end)testCaseProperty= header.substring(start+1,end)
vXsrf=testCaseProperty
log.info("Current xsrf: " + vXsrf)////////////////
log.info(" Current WAF-XSRF-TOKEN header: " + header)
start=header.indexOf(" WAF-XSRF-TOKEN=")
log.info(" Current WAF-XSRF-TOKEN start: " + start+1)end=header.indexOf("; Path=/, ")
log.info(" Current WAF-XSRF-TOKEN end: " + end)testCaseProperty= header.substring(start+1,end)
vWafXsrf=testCaseProperty
log.info("Current wafxsrf: " + vWafXsrf)////////////////
log.info(" Current JSESSIONID header: " + header)
start=header.indexOf("JSESSIONID=")
log.info(" Current JSESSIONID start: " + start)end=header.indexOf("; Path=/com.avaloq")
log.info(" Current JSESSIONID end: " + end)testCaseProperty= header.substring(start,end)
vJsessionId=testCaseProperty
log.info("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 )
log.info("Current testStepName: " + testStepName);if ( testStepName != 'firstLoginCookie' && testStepName != 'SetXSRFheadersForAll') {
log.info("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=/com.avaloq.afs.rest.services; Secure')
//testRunner.testCase.testSteps[testStepName].testRequest.requestHeaders=headers
testRunner.testCase.testSteps[testStepName].testRequest.requestHeaders=headers}
}Thanks
Regards, Reto
- Happened to write it some time ago for a forum request. Could not get that thread, but here is the script that you can try.
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/AddCookiesToNextRequest.groovy