来自同一 txt 文件的多个值

Multiple values from same txt file

我一直在使用此脚本从文件中加载以换行符分隔的值,以发送具有不同值的请求。

def size 
File valueFile = new File("C:\values\myValueFile.txt")
File valueFile2 = new File("C:\values\myValueFile2.txt")
List lines = valueFile.readLines()
List lines2 = valueFile2.readLines()
size = lines.size.toInteger()
def myProps = testRunner.testCase.getTestStepByName("MyProperties") 

for( counter in 0..size-1) 
{
tempValue = lines[counter]
tempValue2 = lines2[counter]
myProps.setPropertyValue("Value", tempValue)
myProps.setPropertyValue("Value2", tempValue2)
log.info tempValue
log.info tempValue2
testRunner.runTestStepByName("updateBusinessTrip")
}

如何让它从用“;”分隔的同一个文件加载值? txt 文件看起来像这样:

Value1;Value2
Value1.1;Value2.1
Value1.2;Value2.2

如果我得到你...:[=​​13=]

选项 1:

tempValue = lines[counter].split(/;/)
myProps.setPropertyValue("Value", tempValues[0])
myProps.setPropertyValue("Value2", tempValue[1])

或选项 2:

(tempValue, tempValue2) = lines[counter].tokenize(';')
myProps.setPropertyValue("Value", tempValues)
myProps.setPropertyValue("Value2", tempValue2)

或另一个:

File valueFile = new File("C:\values\myValueFile.txt")
def myProps = testRunner.testCase.getTestStepByName("MyProperties") 
valueFile.splitEachLine(/;/) { items ->
    myProps.setPropertyValue("Value", items[0])
    myProps.setPropertyValue("Value2", items[1])
    log.info tempValue
    log.info tempValue2
    testRunner.runTestStepByName("updateBusinessTrip")
}