Raj Raj - 1 year ago 193
reST (reStructuredText) Question

Checking HTTP status codes in groovy

I have created a

service and I am testing it in
In a test case I want to verify the
response status codes in

I have tried using the following:

def value = messageExchange.responseHeaders["#status#"]

assert value==200

But it always gives the error and doesn't validates.(The test I am using does returns 200 status code, but I don't know how to put the groovy correctly)

Can anyone plz guide me. I dont want to perform
operation in the groovy. I am performing
separately using soapui and I just want to test the status codes.

Answer Source

This is going to be very useful for future use. I did some searching and found a post regarding this at the SoapUI forum.

I tested it with an HTTP step (sorry, I don't have any rest services to use) and it works well. Luckily, SoapUI handles most all requests the same way so it should work for you as well.

And the raw code:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def httpResponseHeaders = context.testCase.testSteps["testName"].testRequest.response.responseHeaders
def httpStatus = httpResponseHeaders["#status#"]
def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]

log.info("HTTP status code: " + httpStatusCode)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download