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 following parameters sent inside trans.log file.
<v:template>
<v:name>purchase-all</v:name>
</v:template>
- Actually I have to assert weather <v:name>purchase-all</v:name> is present or not inside trans.log file.
Note: Actually this file generally contains large data. This field<v:name>purchase-all</v:name> might be present earlier before sending my purchase request. So I need to validate after only sending purchase request API.
Can you please help me achieving this using ReadyAPI 2.0
Thanks in advance
Regards
Vishal Pachpute
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.