How to add assertion for HTTP 204 content in REST

2019-05-29 21:39发布

问题:

When I run the REST request, my response is

HTTP/1.1 204 No Content Date: Fri, 01 Oct 2010 17:18:11 GMT X-Response-ID: 10016

How to verify this? Because it is header i guess. How to add assertion for this? When i decloare

回答1:

You can use the method messageExchange.responseHeaders[field] to access the HTTP header fields like #status*, Content-Type, Accept etc.

def http_status = messageExchange.responseHeaders["#status#"][0]
assert http_status.contains("204")


回答2:

import com.eviware.soapui.support.XmlHolder

def holder = new XmlHolder( messageExchange.responseContentAsXml )
def node = holder.getDomNode( "//data[1]/@contentType" )

assert node != null
assert((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["#status#"]).containsValue("HTTP/1.1 204 No Content")


标签: rest