Featured Posts

Read Response Headers in SoapUI using Groovy Script

SoapUI is one of the Web service testing tool. Many times we have scenarios to validate the headers values in the response weather it might be RESTful service or SOAP service.

SoapUI has many inbuilt assertions. The assertions "Valid HTTP status codes" and "Invalid HTTP status codes" can be used validate the response status code. Which is shown in the below screen.

response status code

But the tool doesn't have any inbuilt assertions to get any specific response header value to validate it. We can do this using Groovy script in SoapUI.

groovy script we can read any specific header value

From the above image, the response has seven headers values including status code. Using the below groovy script we can read any specific header value.
def val = messageExchange.getResponseHeaders()["Content-Type"][0]
log.info val
assert val == "text/xml; charset=UTF-8" : "Content type not valid"
The above Groovy Script can be used in "Script Assertion" to read and validate the response content type as "text/xml". If we need to read the Response headers value from "Groovy script" test step then we can use the below script.
def val = testRunner.testCase.testSteps['add'].testRequest.response.getResponseHeaders()["Content-Type"][0]
log.info val
assert val == "text/xml; charset=UTF-8" : "Content type not valid"
The below code snippet can be used to read all Header values from the response using groovy script.
def val = messageExchange.getResponseHeaders()
val.each
{
    k,v ->
    log.info "name ="+k+", value = "+v
}

Search
Sponsors
Techie##
###
We will keep You Updated...
Sign up to receive breaking news as well as
receive other site updates!
Subscribe via RSS Feed subscribe to feeds
Sponsors
Popular Posts
Sponsors
Recent Stories
Connect with Facebook
Google Connect
Recent Comments