我儘可能嘗試使用連續的語句返回與響應順序在SOAPUI論壇張貼這是行不通的。
而不是你的groovy代碼作爲一個調度腳本我的目的是使用以下groovy代碼作爲解決方法,它包括使用一個列表來保持您的響應按期望的順序,並保持這個列表在context
更新它使用下面的代碼每次:
// get the list from the context
def myRespList = context.myRespList
// if list is null or empty reinitalize it
if(!myRespList || !myRespList?.size){
// list in the desired output order using the response names that your
// create in your mockservice
myRespList = ["Response 2","Response 3","Response 4","Response 7"]
}
// take the first element from the list
def resp = myRespList.take(1)
// update the context with the list without this element
context.myRespList = myRespList.drop(1)
// return the response
log.info "-->"+resp
return resp
此代碼的工作像您期望的,因爲context
是保持清單,每次該腳本返回下一個響應,當列表爲空再次重新填充它的重新啓動循環以相同的順序。
,當我用這個mockService我得到後續的腳本日誌的說明:
編輯
如果爲OP您與您的SOAPUI版本,因爲返回的字符串問題在方括號之間,如:[Response 1]
,使用以下方法更改元素從陣列中獲取的方式:
// take the first element from the list
def resp = myRespList.take(1)[0]
代替:
// take the first element from the list
def resp = myRespList.take(1)
注意[0]
。
通過此更改,返回字符串將是Response 1
而不是[Response 1]
。
在這種情況下,腳本將是:
// get the list from the context
def myRespList = context.myRespList
// if list is null or empty reinitalize it
if(!myRespList || !myRespList?.size){
// list in the desired output order using the response names that your
// create in your mockservice
myRespList = ["Response 2","Response 3","Response 4","Response 7"]
}
// take the first element from the list
def resp = myRespList.take(1)[0]
// update the context with the list without this element
context.myRespList = myRespList.drop(1)
// return the response
log.info "-->"+resp
return resp
希望這有助於
@albciff - 這是一個有趣的問題。你的解決方案沒有回答我的問題;它並沒有真正的工作。 (請仔細閱讀並查看我在列表中分配字符串的方式時發現的奇怪之處)。然而,這非常有幫助,並構成了我解決方案的中堅力量。 – jamescollett
@albciff親愛的同事,我應該很樂意爲您提供榮譽,但我也注意到您的解決方案完全如所提供的那樣存在缺陷。方括號不是詞典風格的選擇;由於Groovy字符串操作的奇怪效果,它們是必需的。沒有它們,它不起作用。至少對我來說這是奇怪的。我以爲我明確表示了。由於除了接受它作爲解決方案外,沒有辦法爲您的貢獻付款,所以我會做這件事,但其他讀者注意到必要的改動。我希望能減輕你的煩惱。 – jamescollett
我不在乎答案是否被接受......既不是關於榮譽(它是什麼意思?)我對你的評論感到憤怒......可能我過度反應,但答案對我有用,我感到有點生氣(太多了)......我想爲我的反應道歉......當然,如果你覺得這確實不能解決你的問題,那麼你可以自由地接受這個問題。 – albciff