我是GROOVY腳本的新手。 我觸發從soapUI的,這基本上不會登錄到數據庫並返回cookie作爲報頭使用GROOVY腳本將Cookie添加到SoapUI中的標頭
我需要Groovy腳本,其可以採取cookie (EDEV)
的價值的一部分的請求[標記爲紅色在上面的圖片中]並將值傳遞給TestSuite中的所有其他請求。
目前我使用下面的GROOVY腳本來實現這一點,但無法做到這一點。有人可以幫忙嗎?
import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport
def myCookieStore = HttpClientSupport.getHttpClient().getCookieStore()
def val = testRunner.testCase.testSteps['Login'].testRequest.response.getResponseHeaders()
def re = /(EDEV=.*,)/
def matcher = (val =~ re)
def cookie = matcher[0][0]
def map=[:]
testRunner.testCase.testSteps['Login2'].testRequest.requestHeaders=map
def headers=testRunner.testCase.testSteps['Login2'].testRequest.requestHeaders
headers.put('Cookie', cookie)
testRunner.testCase.testSteps['Login2'].testRequest.requestHeaders=headers
哪裏Login
爲登錄和Login2
測試用例是目標測試用例其中cookie值需要傳遞並添加到請求頭。
我檢查了http://stackoverflow.com/questions/20640173/how-do-i-get-a-cookie-from-a-soapui-response-using-a-groovy-test-step
這個答案,並對我的腳本做了一些編輯,但仍然無法在下一個請求中看到EDEV cookie。
可能的重複[如何從使用Groovy測試步驟的SoapUI響應中獲取Cookie?](http://stackoverflow.com/questions/20640173/how-do-i-get-a-cookie-from -a-soapui-response-using-a-groovy-test-step) – SiKing
它不適用於http://stackoverflow.com/questions/20640173/how-do-i-geta-a- cookie-from-a-soapui-response-using-a-groovy-test-step – Sammy
在你的代碼的哪一點你正在從'myCookieStore'中讀取cookies?!?! – SiKing