我如何使用Groovy的测试步骤了SoapUI响应饼干吗?
我想这Groovy代码,但它返回零块饼干(或空)。 这个代码是立即运行一个标准的REST请求返回与下面的头的结果后的测试步骤的一部分:
Set-Cookie: JSESSIONID=45C5E845A0C117E22D26DB04A64E5FD8; Path=/tcompany; HttpOnly
而我使用的检索不到的Cookie Groovy脚本是这样的:
import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport
def myCookieStore = HttpClientSupport.getHttpClient().getCookieStore()
def myCookies = myCookieStore.getCookies()
def sessionCookie
//log.info("Test:" + myCookies.get(0).getValue() )
if ( myCookies.size() > 0 ) {
myCookies.each {
log.info( "Cookie: " + it.name )
if( it.name == "JSESSIONID" ) {
sessionCookie = it
log.info("Found JSESSIONID cookie: " + it.value )
}
}
} else {
log.info("No cookies found in cookie store.")
}
//assert myCookies[0].value().contains("JSESSIONID")
return sessionCookie
我找到了解决该问题的技巧 ,但看来这是其不正常的方式做到这一点:
def val = testRunner.testCase.testSteps['REST Test Request 1'].testRequest.response.getResponseHeaders()
log.info("---- all headers -------")
val.each() { hdrs ->
log.info hdrs
}
log.info("---- cookie jar contents -------")
def cjar = val.get("Set-Cookie")[0]
log.info ( "Cookie Jar: " + cjar )
def cookies = cjar.tokenize("\\;")
log.info("---- cookies -------")
cookies.each() { cookie ->
log.info "Cookie: " + cookie
}
log.info("---- separated -------")
cookies.each() { cookie ->
def pair = cookie.tokenize("\\=")
log.info( "[- Key: " + pair[0] + ", Val: " + pair[1] + "-]" )
}
log.info("---- end -------")