检查多个数组中的值
Checking a value across multiple arrays
我有一个名为 'flights' 的上下文 属性。我想检查这个 属性 是否没有值,然后转到 'Iteration' 测试步骤,否则将 属性 的第一个值设置为测试用例 属性 .
现在我要做的是使用此测试用例 属性 值与几个数组进行比较。以下是场景;
检查值是否在 villas 数组中,如果在 villasCount 中 +1,否则在 hotels 数组中检查,如果在那里则 +1 到 beachCount,否则 +1 到 noCount。
代码如下:
// define properties required for the script to run.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def dataFolder = groovyUtils.projectPath
//Define an empty array list to load data from datasheet
def dataTable_properties = [];
int villasCount = context.getProperty("villasCount")
def lines = new File(dataFolder + "/Test.csv").readLines()
def villas = []
lines.eachWithIndex { line, index ->
if (index) {
def data = line.split(',')*.trim()
if (data[0]) villas << data[0]
}
}
log.info "Villas : ${villas}"
context.setProperty("villasCount", villasCount)
可能是这样的:
for(f in flights){
if(villas.contains(f)){
villasCount = villasCount + 1
}
}
不能 100% 确定您需要比较什么,但您可以轻松扩展它以检查您想要的任何内容。
如果这还不够,请提供有关您尝试比较的内容的更多信息。
我有一个名为 'flights' 的上下文 属性。我想检查这个 属性 是否没有值,然后转到 'Iteration' 测试步骤,否则将 属性 的第一个值设置为测试用例 属性 .
现在我要做的是使用此测试用例 属性 值与几个数组进行比较。以下是场景;
检查值是否在 villas 数组中,如果在 villasCount 中 +1,否则在 hotels 数组中检查,如果在那里则 +1 到 beachCount,否则 +1 到 noCount。
代码如下:
// define properties required for the script to run.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def dataFolder = groovyUtils.projectPath
//Define an empty array list to load data from datasheet
def dataTable_properties = [];
int villasCount = context.getProperty("villasCount")
def lines = new File(dataFolder + "/Test.csv").readLines()
def villas = []
lines.eachWithIndex { line, index ->
if (index) {
def data = line.split(',')*.trim()
if (data[0]) villas << data[0]
}
}
log.info "Villas : ${villas}"
context.setProperty("villasCount", villasCount)
可能是这样的:
for(f in flights){
if(villas.contains(f)){
villasCount = villasCount + 1
}
}
不能 100% 确定您需要比较什么,但您可以轻松扩展它以检查您想要的任何内容。 如果这还不够,请提供有关您尝试比较的内容的更多信息。