Combine TestNGListener with log4j for selenium result reporting

This post will explain the integration of any java logger (let’s say Log4j) with ITestListener to customise result output and print the same to log file.

We have seen testNG and it’s listener ITestListener to customise the result output.

 

Watch details here

Log4j maven dependency

Use below dependency –

Log4j properties file

Create a new folder “resources” under “src > main” folder, and create a new file log4j.properties under src > main > resources with below content

 

Project folder structure

Implement ITestListener interface

Create a package “testNGListener.Logger”, and then create TestListeners.java

Create a common Log class

Log.java

 

Test class or Test case

TestSample.java

 

testng.xml

Run testng.xml, a folder “Log4j” will be created under current project with application.log file

 

References

For more info on log4j, you can refer http://www.mkyong.com/logging/log4j-hello-world-example/

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *