vpachpute1
8 years agoFrequent Contributor
ReadyAPI 2.0: To apply assertions inside log files
Hi I have one scenario that, 1 Purchase using API. And validate response - Working fine. 2. Inside my application, there is one log file as trans.log - After the purchase, there are follow...
- 8 years ago
If you are able to clear the trans.log file and have access to it, you can use the following groovy script:
PrintWriter writer = new PrintWriter("/path/to/log/trans.log"); writer.print(""); writer.close();
That will zero out the file and erase ALL contents of it. From there, you need a groovy script to parse the contents of the log.
def fileContents = new File("/path/to/log/trans.log").text.split("\n"); for (line in fileContents) { if (line.contains("<v:name>purchase-all</v:name>")) { log.info(line); } }
That's a basic proof of concept that you should be able to modify to do what you want.