Forum Discussion

rvteja1990's avatar
rvteja1990
Occasional Contributor
10 years ago
Solved

Assertion for raw response

I have been trying to create an assertion for raw response. I got a requirement in which whenever i see a response with Invalid URI in headers, it should fail. This is how it is displayed in response "HTTP/1.1 500 Invalid URI - /xyz/abc/123". 

 

In the above header whenever i see "Invalid URI" assertion should fail.

 

When i checked forums i found a script assertion, with which i have modified it like this. However its failing since the URI part is not mentioned in expectedHTTPResponse. I would like to make it generic, such a way that whatever may be the URI, whenever i encounter Invalid URI it should fail the assertion.

 

Below is the piece of code:

 

def expectedHTTPResponse = ['HTTP/1.1 500 Invalid URI']
def headers = messageExchange.response.responseHeaders
def actualHTTPResponse = headers['#status#']
assert expectedHTTPResponse == actualHTTPResponse, "Invalid URI" 

 

Can anyone help me with this? Any other possible solutions to achieve this?