SoapUI設置Cookie

因為.NET寫的Web Service的方法是須要驗證session的。cookie

須要先call方法Login之後才能使用其它的方法。最近剛在學用SoapUI測試soap的API,剛好能夠通過Groovy Script來實現設置login之後獲得的cookie。session

 

測試工程以下圖,滑鼠右擊Test Steps,新增Groovy Script。ui

 

Script以下:spa

import com.eviware.soapui.support.types.StringToStringMap

def cookiesList = testRunner.testCase.getTestStepByName("login").testRequest.response.responseHeaders["Set-Cookie"]
log.info cookiesList
 
//Get the cookie
String cookieNew = cookiesList.get(0)
log.info "cookie : "+cookieNew

//Put cookie to a StringMap
def cookieMap = new StringToStringMap()
cookieMap.put("Cookie",cookieNew)

testRunner.testCase.getTestStepByName("BsrDataAndLog").testRequest.setRequestHeaders(cookieMap);
相關文章
相關標籤/搜索