How to use custom listener to generate single custom log and report file using robot framework effectively

559 views
Skip to first unread message

pratap raju

unread,
Jun 4, 2017, 7:24:07 AM6/4/17
to robotframework-users
Hello friends,

I am trying to create my own log file and report by using custom listener. Currently i am overiding start suite and end suite methods. 
def start_suite(self, name, attrs):
def end_suite(self, name, attrs):
using start_suite method to create a new log and report  file and end_suite method to close the log and report file. 
In between i am writing in to the log and report files during the course of test run by overiding some more method of start_test, end_test, start_keyword, end_keyword. 

The reason why we wanted the custom log and report file is we are using the unix platform and these files should be .txt and should be having very minimal information as per my project need.This needs to be integrated in to the different quality dashboard.

i am creating a new report and log file for each test run. All looks good till here as long as i specifiy a single .robot file when running robot tests as below.
python -m robot.run  -i devicecapability  --listener path\customListener.py --loglevel INFO --listener path\customListener.py  path\caf.robot


But if am providing suite parameter  which has many sub suites under it, it is generating multiple report and log fles files one for each suite. 
running a suite as shown below.
python -m robot.run  -i tagname --suite nextGenAutomation.testSuites  <pathtotestsuite\workspaceRobotframework\nextGenAutomation>.

Any pointers on what is the good way to generate your own log files and report files. Which is the listener method which gets called only once during the whole test run as part of the test execution where i can create or initialize my log and report file for each test execution.





Bryan Oakley

unread,
Jun 4, 2017, 8:44:05 AM6/4/17
to robotframework-users
I think you're asking how to create a single log file rather than one for each suite, is that correct?

Assuming you are using version 2 of the listener API, the start_suite method gets a dictionary of attributes. One of the attributes is "id", which uniquely identifies the suite or test case. In your start_suite method you can check for this, and only open your file if the id is equal to "s1".  "s1" will be given to the only suite if you're running a single suite, or it will be set for the virtual suite that serves as the root suite when running two or more actual suites. 


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

pratap raju

unread,
Jun 4, 2017, 11:05:15 PM6/4/17
to robotframework-users
Thank you very much for the quick response.
Since i might end up in running a suite all the time instead of a specific .robot file. I will choose to use s1 as my suite name and open my log and report only when i recieve the suite name as s1. 

Bryan Oakley

unread,
Jun 5, 2017, 7:47:31 AM6/5/17
to robotframework-users
I don't understand your reply. You don't need to name your suite anything special. The id of "s1" will always refer to the very first suite that runs. It might represent an actual .robot file if you're running a single .robot file, or it might represent a virtual suite that is created to serve as the root suite for all of the other actual suites. Regardless, the very first time start_suite is called, the id will always be "s1" which you can use to do some special one-time setup of your reporting system.

pratap raju

unread,
Jun 5, 2017, 9:23:46 AM6/5/17
to robotframework-users
Got it. Thank you very much
Reply all
Reply to author
Forward
0 new messages