Forum Discussion
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.
Hi Rao
Before practicing your code, I would say appreciate very much.
I feel I need to give you more details about my questions.
My task is to use soapUI to test the API which is already deployed to test box. Before using soapUI, I have tried login from web browser, no matter FF or Chrome and open web development tool (click F12 as we known). From the network tab showing, I can see the first method is login, which is Post method, then lots of Get methods and another Post method which is logevent. From that Post method, I can see the token Id.
I thought I can use soapUI to do the same things. Am I right?
I recon, the first step of request is login to the box, which should be a Post method. Yes it seems works and got http headers:
Date Wed, 18 Nov 2015 20:08:32 GMT
Transfer-Encoding chunked
#status# HTTP/1.1 200 OK
Expires Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive timeout=10
Content-Type text/html;charset=UTF-8
Connection Keep-Alive
X-Powered-By Servlet 2.5; JBoss-5.0/JBossWeb-2.1
X-Powered-By JSF/1.2
Pragma no-cache
Cache-Control no-cache
Cache-Control no-store
But the size is quite different from what I got from web browser development tool Network tab showings. Why?
This is my first question.
Then I tried using groovy scripts and hope to get more details of Cookies but no luck so far.
After the first step of login, I expect to use the soapUI request with Get method to test the API - to get the bundle of json data which the API should return. It works on web browser of course. But I am stuck on soapUI...
I am wondering how to fetch the useful parameter from the first step and then HOW to re-use them to the following requests to test the API.
This is my second question.
Hope you can help?
Thank you very much.
Cheers
swee
- nmrao10 years agoChampion Level 3I will later go thru your reply and come back.
Related Content
- 7 years ago
- 10 years ago
Recent Discussions
- 8 days ago