SOAPUI Groovy-将列表项附加到属性
我是新的SoapUi和Groovy; 在每次迭代中,尝试从前面的步骤请求(在Get Media List下面调用)的响应中设置和更新测试用例级别2属性。 每次迭代我都需要将响应中的项附加到属性中 以下是脚本:SOAPUI Groovy-将列表项附加到属性,groovy,eval,soapui,Groovy,Eval,Soapui,我是新的SoapUi和Groovy; 在每次迭代中,尝试从前面的步骤请求(在Get Media List下面调用)的响应中设置和更新测试用例级别2属性。 每次迭代我都需要将响应中的项附加到属性中 以下是脚本: def fullMediaNameList = context.expand( '${#TestCase#MediaNameList}' ) def currMediaNameList = context.expand( '${Get Media List#o_mediaNameList}
def fullMediaNameList = context.expand( '${#TestCase#MediaNameList}' )
def currMediaNameList = context.expand( '${Get Media List#o_mediaNameList}' )
AppendItemsToPropertyList(fullMediaNameList, currMediaNameList,"MediaNameList")
def AppendItemsToPropertyList(fullListStr, currListStr, propToUpdate)
{
def fullList = []
if (fullListStr != null && fullListStr != "")
{
//cast to list
fullList = Eval.me(fullListStr)
}
//specific list to append
def currList = []
if (currListStr != null && currListStr != "")
{
//cast to list
currList = Eval.me(currListStr)
}
fullList.addAll(fullList.size(), currList)
testRunner.testCase.setPropertyValue( propToUpdate, fullList.toString() )
这个方法我叫了两次;介质id属性一次,该属性正常工作!
以及另一个名为MediaNameList的属性,它失败并出现以下错误:
org.codehaus.groovy.control.multiplecompationerrorsException:启动失败:Script1.groovy:1:意外标记:HD@line 1,第21列。[DMAX HD、RTL Nitro HD、ZDFNeo HD、Deutsches Wetter Fernshen、Tele 5 HD、sixx HD、Sat.1 Gold、MTV、E!Entertainment、迪士尼频道]^1第8行错误
为什么会这样?若我理解正确的话,它在字符串转换方面有问题,并且尝试了其他命令而不是Eval.me,但并没有帮助。
e、 g.fullList=Arrays.aslistfulllliststr
欢迎其他解决方案!
提前感谢,您的问题是您认为您有一个字符串列表,但是它们没有引号,因此Groovy试图将其作为变量列表进行求值。您将需要以下内容:
def fullMediaNameList = context.expand( '${#TestCase#MediaNameList}' )
def fullList = [] // declare empty array
if (fullMediaNameList != null && fullMediaNameList != "") {
// break up the fullMediaNameList at commas, and itterate over the parts
fullMediaNameList.split(',').each {
// trim off leading or trailing whitespace from each part, and append as new element to the array
fullList << it.trim()
}
}
成功了!使用tokenize进行小改动:
def fullList = []
if (fullListStr != null && fullListStr != "")
{
//cast string to string list:
// break up the fullMediaNameList at commas, and itterate over the parts
fullListStr.tokenize(',[]').each {
// trim off leading or trailing whitespace from each part, and append as new element to the array
fullList << it.trim()
}
}
非常感谢你: