我尽可能尝试使用连续的语句返回与响应顺序在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