richie
6 years agoCommunity Hero
Script Assertion To Grab 4 'Set-Cookies' To Set 1 'Cookie' Header In Follow Up Request
Hi,
This is related to my other 'cookie' post - but that other post has side tracked onto another issue I need to solve - so I've created a second post with a specific issue.
A while back...
- 6 years ago
Finally, simulated the issue.
Here you go:
def nextStepName = 'REST Request' def headerToLook = 'Set-Cookie' def headerToSet = 'Cookie' def nextRequest = context.testCase.testSteps[nextStepName].httpRequest def headers = nextRequest.requestHeaders def showHeaderCount = {msg -> log.info "Header count ${msg} is: headers.size()" } showHeaderCount('before') if (headerToSet in headers.getKeys()) { headers.remove(headerToSet) showHeaderCount('after') } if (messageExchange.responseHeaders.containsKey(headerToLook)) { log.info "Found ${headerToLook} in the response headers" def cookiez = messageExchange.getResponseHeaders().get(headerToLook) def computedValue = cookiez.collect { it.split(';').first()}.join('; ') log.info "Value for Cookie header is evaluated to : ${computedValue}" headers.put(headerToSet, computedValue) log.info 'Headers updated' nextRequest.requestHeaders = headers log.info headers } else { log.warn "Not Found ${headerToLook} in the response headers" }