SoapUI设置Cookie


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

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

 

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

 

Script如下:

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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM