我如何使用Groovy的测试步骤了SoapUI响应饼干吗?(How do I get a Cooki

2019-10-19 03:38发布

我如何使用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 -------")

Answer 1:

您的代码看起来好像没什么问题。 唯一的问题是,(我想!)的标题应该是“曲奇”,而不是“设置Cookie”。 这可能帮助: http://siking.wordpress.com/2013/07/25/soapui-cookie-management/



Answer 2:

对于SOAPUI测试,我添加标题: http://mariemjabloun.blogspot.com/2014/11/set-webservice-authentication-and-set.html



文章来源: How do I get a Cookie from a SoapUI response using a Groovy test step?