Getting Logs out of Serenity Cucumber

2,065 views
Skip to first unread message

Santosh Pillai

unread,
Sep 5, 2016, 10:43:12 AM9/5/16
to Serenity BDD Users Group
Hi,

I'm using Serenity with Cucumber. Can anyone please suggest the best ( and preferred) way of creating logs and storing them in an external file?

Thanks.

John Smart

unread,
Sep 5, 2016, 10:58:21 AM9/5/16
to Santosh Pillai, Serenity BDD Users Group
Hi,

What sort of logs are you trying to produce?

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Santosh Pillai

unread,
Sep 6, 2016, 4:05:04 AM9/6/16
to Serenity BDD Users Group, santosh....@gmail.com
Hi,

Looking for a simple log file that has a record of every test step of my Test execution with some additional attributes like - TimeStamp 

For example.

 2016:09:05 - 05:05: 05 :  Navigated to login Page.
 2016:09:05 - 05:05: 05 : Entered User name
 2016:09:05 - 05:05: 05 : Entered Password.
 2016:09:05 - 05:05: 05 : Clicked on Logn in Button. 

Please let me know if more information is need. 

Thanks,
Santosh

Santosh Pillai

unread,
Sep 6, 2016, 10:48:50 AM9/6/16
to Serenity BDD Users Group, santosh....@gmail.com
I got this using slf4j-log4j12

Thanks.

John Smart

unread,
Sep 6, 2016, 10:49:41 AM9/6/16
to Santosh Pillai, Serenity BDD Users Group
Glad to hear it! Maybe you could share the details in case others would like to do the same thing?

To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-users+unsubscribe@googlegroups.com.
To post to this group, send email to thucydides-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +44 7398 832273
Making smart teams collaborate better
http://johnfergusonsmart.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Product Planning, BDD Requirements Discovery,  BDD, TDD and Clean Coding, and Advanced BDD Test Automation.
___________________________________________________

Santosh Pillai

unread,
Sep 7, 2016, 12:00:37 PM9/7/16
to Serenity BDD Users Group, santosh....@gmail.com
Here is what I did. 

1- if we are creating our project using a pre-defined archetype then the POM file will have a dependancy - 
<dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-simple</artifactId>

            <version>1.7.7</version>

 </dependency>

 
  slf4j is a facade that uses many famous logging libraries like log4J, logback etc. We can use any one of these. 


2. Change the artifact ID to 'slf4j-log4j12' or whatever the latest log4j version is.  So now the updated dependency is :
<dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-log4j12</artifactId>

            <version>1.7.7</version>

 </dependency>


3. Now we can use log4J for logging purposes. 

4. Create a log4J.properties file. It can have the following configuration. 

# Root logger option

log4j.rootLogger=INFO, file, stdout


# Direct log messages to a log file

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=Test.log   //This is the file where your logs will be saved in the root folder(where we have the POM)

log4j.appender.file.MaxFileSize=10MB

log4j.appender.file.MaxBackupIndex=10

#log4j.appender.file.Append=false

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


# Direct log messages to stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.Target=System.out

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


3. Place this file in src/test/resources. 

4. Now when you run your tests with "" in the 'serenity.properties file".  you can get logs as following. 



5. You can also added log messages in your code like :

Logger logger = LoggerFactory.getLogger(Utils.class);

logger.info("Clicked on Element" + element);


 Hope that helps.

Marius Pojar

unread,
Sep 19, 2016, 10:47:09 AM9/19/16
to Serenity BDD Users Group, santosh....@gmail.com
Hi Santosh,

Did you tried to put in the log the stack trace in case of failure?
I am trying that, i know that the step has falied StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed(), but i need the stack error.

Thanks
Reply all
Reply to author
Forward
0 new messages