divman
10 years agoContributor
Resolved:Get HTTP Response Code
Hi,
Sorry if this is repeated question, but i couldn't get the exact answer what i need.
I send a REST service and get the response back. In JSON tab, i get the response what i need to get and am validating that with my expectation. In Raw tab, i get the response like below.
Here i need to get the first line out as "HTTP/1.1 200 OK" or the HTTP Error Code as "200 OK". Is there any way yo get that out?
Sorry if this is repeated question, but i couldn't get the exact answer what i need.
I send a REST service and get the response back. In JSON tab, i get the response what i need to get and am validating that with my expectation. In Raw tab, i get the response like below.
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Date: Wed, 14 Jan 2015 15:33:32 GMT
Pragma: no-cache
Content-Length: 122
Content-Type: application/json
Expires: 0
Accept: application/json
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=2bnSJ2MMvL2wKNlQ6y3tZQy9vpv6Dv0Bh1Y6YprZvmWh76T5KV7K!-1868580631; path=/; HttpOnly
Set-Cookie: _WL_AUTHCOOKIE_JSESSIONID=TPX8bnRvzHF7C4U6e18T; path=/; secure; HttpOnly
X-Version-Served: 1
X-Powered-By: Servlet/2.5 JSP/2.1
X-Frame-Options: DENY
{"userReferenceId":"1zdYKGMazTOwKmgZIKbHz1Str3Pr9gHCUwqHdoEs5bM=","accessRoleId":79,"accessRoleAssignmentStatus":"ACTIVE"}
Here i need to get the first line out as "HTTP/1.1 200 OK" or the HTTP Error Code as "200 OK". Is there any way yo get that out?
- Hope i got it.
As i mentioned earlier, use script assertion.
headers["#status#"] returns List. Looks you are asserting with string.
So, you may use value coming from excel file for variable 'excelExpectedValue'def headers = messageExchange.getResponseHeaders()
log.info headers["#status#"]
assert ['HTTP/1.1 200 OK'] == headers["#status#"]
//log.info messageExchange.getResponseContent()
headers["#status#"] instanceof List
def actualStatus = headers["#status#"].get(0)
def excelExpectedValue = '200 OK'
def expectedStatus = 'HTTP/1.1 '+excelExpectedValue
assert expectedStatus == actualStatus