i want to extract a value of token in a line from a text file.
The line from the text file is:
<response>{"timestamp": "2013-11-12T14:55:43Z", "data": {"profile": null, "ticket": "f644231-6d46-44c7-add6-de3a4422871e", </response>
groovy file is:
// 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)
So here it's not storing any value in my variable ticket. Any help, please
Replace
def data= file.eachLine { line ->
// check if the line contains your data
if(line.contains('"ticket":')){
return line
}
}
With
def data= file.filterLine { line ->
line.contains('"ticket":')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With