0

当我调用发送带有“Set-Cookie”标头的响应的 Web 服务时,soapui 会缓存 cookie 以供后续调用。如何在后续调用中清除这些 cookie?

或者有没有办法从响应中的端点“不接受”cookie?

我正在使用免费的 Soap UI 4.5.0

4

2 回答 2

1

在 eviware 的论坛上查看这篇文章,其中一个回复显示了如何清除 cookie

于 2013-09-04T17:34:09.543 回答
1

我在另一个答案中阅读了来自 Abhishek的链接,并在此链接上找到了我的答案:

对于任何正在寻找答案的人,这是我现在使用的:

基本上,您必须使用要运行的请求创建一个测试用例,并且您将在 TestSteps 中获得一个脚本编辑器,您可以在其中使用以下 groovy 脚本。

import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport

def myCookieStore = HttpClientSupport.getHttpClient().getCookieStore()

def myCookies = myCookieStore.getCookies()

// find the session cookie
def sessionCookie
myCookies.each {
    // print all of them 
    log.info(it.name + " = " + it.value)
    if (it.name == "JSESSIONID"){
        sessionCookie = it
    }

}


// if you want to update the cookie value
// sessionCookie.value = "new cookie value here..."


// deleting all cookies
myCookieStore.clear()

// to delete only specific
//if (sessionCookie != null) {
//  sessionCookie.expiryDate = new Date()-1 // yesterday
//  myCookieStore.clearExpired(new Date()-1)
//}

// check if the cookies are really removed
myCookies = myCookieStore.getCookies()
log.info("After Removing Session Cookie");
myCookies.each {
    // print all of them 
    log.info(it.name + " = " + it.value)
}

// if you want to create your own cookie
//import org.apache.http.impl.Cookie.BasicClientCookie
//def myNewCookie = new BasicClientCookie("cookie_name", "cookie_value")
//myNewCookie.version = 1
//myNewCookie.domain = "qa.test"
//myCookieStore.addCookie(myNewCookie)

// or from another cookie
//def myNewCookie = new BasicClientCookie("cookie_name", interestingCookie.value)
于 2013-09-09T21:52:57.233 回答