Forum Discussion
nmrao
11 years agoCommunity Hero
Still not clear what you are looking for exactly from the post.
This may just be helpful information for better understanding of response headers.
http://www.soapui.org/testing-dojo/best-practices/understanding-rest-headers-and-parameters.html
What I understnad for the script you posted is that
- You are getting http headers, not the coockie
Here is script assertion(for your HTTP Request 1 step) instead of additional groovy script for the same (as per my understanding)
- Define a custom property EXPECTED_COOKIE_SIZE and its value at test case level
//Assuming a custom property EXPECTED_COOKIE_SIZE defined with needed value at test case level
def expectedCookieSize = context.testCase.properties['EXPECTED_COOKIE_SIZE'].value as int
def cookie
if (messageExchange.responseHeaders.containsKey('Cookie')) {
log.info "Found Cookie in the response headers"
cookie = messageExchange.responseHeaders['Cookie'].value
log.info "Cookie value : ${cookie}, and its size is : ${cookie.size()}"
assert expectedCookieSize == cookie.size, "Cookie size mismatch"
} else {
log.warn "Not Found Cookie in the response headers"
}
The second question "I expect to do the second Request to Get some json data, but it is never successful." not clear, what do you mean by it? Could please add more details?
nmrao
11 years agoCommunity Hero
Here is slightly improved answer based on the fact that -
- to match data of any given header both in request and response
- provide name of the header you wanted to assert i.e., is response header compared with request
- Say a test case custom property HEADER_NAME and value as 'Cookie' in this case (can be any header in fact)
/** * checks if given HEADER_NAME in request vs response * also its value and size * Assumes, a custom test case property HEADER_NAME is defined with * appropriate value lie Content-Type, Cookie etc., any thing for that matter
* This can be used as Script Assertion **/ def key=context.testCase.properties['HEADER_NAME'].value def isHeaderInRequest = messageExchange.requestHeaders.containsKey(key) def isHeaderInResponse = messageExchange.responseHeaders.containsKey(key) assert isHeaderInRequest == isHeaderInResponse, "Header ${key} cound not found either in request or response" def headerValueInRequest = messageExchange.requestHeaders[key].value def headerValueInResponse = messageExchange.responseHeaders[key].value printLog("Request", key, headerValueInRequest) printLog("Response", key, headerValueInResponse) assert headerValueInRequest == headerValueInResponse, "${key} value mismatch between request and response" assert headerValueInRequest.size() == headerValueInResponse.size(), "${key} value size mismatch" def printLog = { message, key, value -> log.info "${message} - Header - \n${key} : ${value} \nsize : ${value.size()}" }
Hope this is what you are looking for in the first place.