Simple steps to Generate logs in Selenium using TestNG reporter

Logging is most important part in any automation tools which make our script in more readable format.Today we will discuss one easy way to Generate logs in Selenium via TestNG Reporter class.

We have already seen some default reporting which is generated by TestNG and Advance XSLT reports as well.

As a good automation engineer, you should implement logging feature in your script, which helps you to debug your code easily if your script is failing. We have seen how to create log files in Selenium using log4j.

I want to share one more report which is best among all and very handy to use as well. Extent report generates logs and it allows us to attach the screenshot as well which make our report more attractive.

 

Reporter Class in TestNG for Generate logs in Selenium

The Reporter is a separate class in TestNG that is available under org.testng package.

In Selenium you can specify steps, which we are performing so that we can check our output, and in case any issue we can debug at which point our test cases failed.

Let me explain with the help of an example
Scenario 1- We have a script, which has almost 100 steps so if we do not use Reporter or any other reporting feature then we have to check where exactly we are getting the issue. We can use Reporter class here and we can check steps which have executed successfully and where our program has stopped.

Before starting below program make sure Eclipse Selenium and TestNG is installed

 

Generate logs in Selenium

 

Complete program to check Generate logs in Selenium

 

Once you run above program check TestReport

 

Generate logs in Selenium

Now if you want to print on console and html report as well then we have the same method with diff argument

  1. if boolean value set to true then values will come on console and HTML report as well.
  2. if boolean value set to false then values will come on HTML report only.

 

Hope you liked above post. Keep sharing with friends.Comment below if you finding some issues.

Have a nice day 🙂

Like Facebook Page for more updates-Learn-Automation facebook page

Join Selenium Group for discussion and queries- Learn-Automation group

12 Comments

  1. Pratik
  2. jayesh
  3. Swapna
  4. suguna
  5. shubham

Leave a Reply