Forum Discussion
This is the raw response i'm getting:
HTTP/1.1 500 Invalid URI - /xyz/abc/123"
Content-Type: text/xml
X-Backside-Transport: FAIL FAIL
Connection: close
I want to check whether the raw response has "Invalid URI". If it has Invalid URI in response assertion should fail.
Thank you.
- AntonE9 years ago
Alumni
You can use startsWith method to check that a string has a required beginning:
def expectedHTTPResponse = 'HTTP/1.1 500 Invalid URI'
def headers = messageExchange.response.responseHeaders
def actualHTTPResponse = headers['#status#']
assert actualHTTPResponse.size() == 1 && actualHTTPResponse[0].startsWith(expectedHTTPResponse), "Invalid URI"Note that I removed square brackets in expectedHTTPResponse as we compare just one element now.
- rvteja19909 years agoOccasional Contributor
Thanks for your response. I really appreciate your help Anton. Your piece of code works as expected.
I need a small change in this,
Is there any way that we can fail this assertion when it matches with expected HTTP Response (InvalidURI)?
I mean, since its matching with expected HTTPResponse, assertion is valid and its displaying as 'Green'. I would like to see 'Red' color whenever InvalidURI encounters in response. For the rest of all the other responses it should show as 'Green'
- nmrao9 years ago
Champion Level 1
Not sure why it is closed though your issue is not solved.
Here is the change needed:
def unExpectedHTTPResponse = 'HTTP/1.1 500 Invalid URI' def headers = messageExchange.response.responseHeaders def actualHTTPResponse = headers['#status#'] assert !(actualHTTPResponse[0].contains(unExpectedHTTPResponse)), "Found Invalid URI in the response"