我想从文本文件中提取一行中的令牌值。
文本文件中的行是:
<response>{"timestamp": "2013-11-12T14:55:43Z", "data": {"profile": null, "ticket": "f644231-6d46-44c7-add6-de3a4422871e", </response>
Run Code Online (Sandbox Code Playgroud)
常规文件是:
// read the file from path
def file = new File('c:/tmp/response.txt')
// for example read line by line
def data= file.eachLine { line ->
// check if the line contains your data
if(line.contains('"ticket":')){
return line
}
}
testRunner.testCase.testSuite.project.setPropertyValue('ticket',data)
Run Code Online (Sandbox Code Playgroud)
因此,这里的可变票证中没有存储任何值。任何帮助,请
更换
def data= file.eachLine { line ->
// check if the line contains your data
if(line.contains('"ticket":')){
return line
}
}
Run Code Online (Sandbox Code Playgroud)
用
def data= file.filterLine { line ->
line.contains('"ticket":')
}
Run Code Online (Sandbox Code Playgroud)