在groovy context.expand表达式中使用变量

在groovy context.expand表达式中使用变量,groovy,expand,Groovy,Expand,我尝试使用groovy脚本和soapUI自动化测试用例 通过发送soap请求,我得到了一个包含公司列表的响应。 我想做的是核实上市公司的名称。 响应数组的大小不是固定的 所以我尝试了下面的脚本只是为了开始,但是我被卡住了 def count = context.expand( '${Properties#count}' ) count = count.toInteger() def i = 0 while (i<count) ( def response = context.exp

我尝试使用groovy脚本和soapUI自动化测试用例

通过发送soap请求,我得到了一个包含公司列表的响应。 我想做的是核实上市公司的名称。 响应数组的大小不是固定的

所以我尝试了下面的脚本只是为了开始,但是我被卡住了

def count = context.expand( '${Properties#count}' )
count = count.toInteger()
def i = 0
while (i<count)
    (
def response = context.expand( '${getCompanyList#Response#//multiRef['+i+']/@id}' )
 log.info(response)
i=İ+1   
    )

我应该以某种方式将“I”放在“response”定义中。

您在while语句中使用了错误的字符,它应该是大括号(
{}
),而不是括号(
()

这就是为什么错误与第6行的
def
有关,而与
i
变量无关

示例中还有
İ
,这在Groovy中不是有效的变量名

我想你想要这个:

def count = context.expand( '${Properties#count}' )
count = count.toInteger()
def i = 0
while (i<count) {
    def response = context.expand( '${getCompanyList#Response#//multiRef['+i+']/@id}' )
    log.info(response)
    i=i+1   
}
(如果将封口内的
i
替换为
it
,也可以移除
i->
。)

def count = context.expand( '${Properties#count}' )
count = count.toInteger()
def i = 0
while (i<count) {
    def response = context.expand( '${getCompanyList#Response#//multiRef['+i+']/@id}' )
    log.info(response)
    i=i+1   
}
def count = context.expand( '${Properties#count}' )
count.toInteger().times { i ->
    def response = context.expand( '${getCompanyList#Response#//multiRef['+i+']/@id}' )
    log.info(response)
}