2016-08-30 9 views
0

私はこのスクリプトを使用して、異なる値のリクエストを送信するためにファイルから新しい行で区切られた値を読み込みました。同じtxtファイルの複数の値

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 

答えて

0

私はあなたを持っている場合...:

オプション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) 

または別の1:

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") 
} 
+0

偉大な、それは私が必要なものです:) – Kobielak

関連する問題