• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / TestNG Tutorial / Simple steps to Generate logs in Selenium using TestNG reporter

Simple steps to Generate logs in Selenium using TestNG reporter

April 4, 2015 by Mukesh Otwani 20 Comments

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

Syntax-Reporter.log("String", boolean);

 

Complete program to check Generate logs in Selenium

package testngDemo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class ReporterDemo {
    
    @Test
    public void testReport(){
        
        WebDriver driver=new FirefoxDriver();
        
        Reporter.log("Browser Opened");
        
        driver.manage().window().maximize();
        
        Reporter.log("Browser Maximized");
        
        driver.get("http://www.google.com");
        
        Reporter.log("Application started");
        
        driver.quit();
        
        Reporter.log("Application closed");
        
    }

}

 

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

Filed Under: TestNG Tutorial Tagged With: Reporter

Reader Interactions

Comments

  1. Muhammad Zeeshan Ismail says

    November 14, 2020 at 2:00 PM

    Thanks for sharing your knowledge with us. My concept regarding Logs is now cleared and also got the difference between Syso and log.

    Reply
    • Mukesh Otwani says

      November 15, 2020 at 9:41 AM

      Hi Muhammad,

      Glad that my blog post helped you to gain knowledge. You’re always welcome to ask your doubts and I’ll try my level best to answer them.
      Thanks for your appreciation…:)

      Reply
  2. Harsha P says

    March 20, 2020 at 7:36 PM

    Hi mukesh,

    thanks for your great sessions. Which is better log4j or testng log?

    regards,
    Harsha

    Reply
    • Mukesh Otwani says

      March 21, 2020 at 2:20 PM

      Hi Harsha,

      Both are equally good depends on your project requirements. TestNG logs can be written directly into TestNG report while Log4j, can be redirected to any external log file

      Reply
  3. Piyush says

    July 30, 2019 at 7:52 PM

    How to format Reporter.log? Like I wants to print the message in red color

    Reply
    • Mukesh Otwani says

      July 31, 2019 at 6:10 PM

      Hi Piyush,

      Please check this link

      Reply
  4. Aarati says

    March 30, 2019 at 10:41 AM

    hello ,How do I take Repoter.log statement from excel as I have no.of test cases.

    I will really Appreciate for help.

    Reply
    • Mukesh Otwani says

      March 30, 2019 at 2:34 PM

      Hi Aarati,

      Since you are reading from excel, read data from particular excel cell and pass it as parameter to Reporter like Reporter.log(, true);
      How to read from excel, kindly check this link http://learn-automation.com/read-and-write-excel-files-in-selenium/

      Reply
  5. Gaurav Khurana says

    January 15, 2017 at 3:13 PM

    Wow this logging is so easy compared to log4j. Thanks for the easy explanation and it’s so easy to use.

    Also just for everyone knowledge

    Reporter.log(“I am log info”,false)
    Reporter.log(“I am log info”)

    The above two statements are equal and will not print on the console.

    Reply
    • Mukesh Otwani says

      January 19, 2017 at 12:36 PM

      Hi Gaurav,

      Give Reporter.log(“I am log info”,true) to log to appear on console.

      Reply
  6. Pratik says

    October 1, 2016 at 7:56 PM

    Hey Mukesh,

    Thanks a lot for sharing all this knowledge and problems with possible solutions.
    Your blog has helped me a lot to learn Selenium in a very basic to advance.

    Highly appreciate…!!

    Thanks

    Reply
    • Mukesh Otwani says

      October 3, 2016 at 4:29 PM

      Hey Pratik,

      Your most welcome. I am glad to know it helped. Keep visiting and be in touch.

      Reply
  7. jayesh says

    August 16, 2016 at 12:57 AM

    Hi Mukesh – Thanks a lot for keep helping us to understand automation- testing in detail.

    I have a problem here too, can you help with this

    I am trying to attach a screen print inside testng report. this is working fine in index.html report but in emailable report it just html markup the image is not rendering ,when I checked the emailable html file it logged as html escaps, any help on this.. TestNG version is 6.9
    Reporter.log(“” +”“);

    Reply
    • Mukesh Otwani says

      August 18, 2016 at 9:44 AM

      Hi Jayesh,

      Please give a try with extent report also

      http://learn-automation.com/advance-selenium-reporting-with-screenshots-2/

      Reply
  8. Swapna says

    July 24, 2016 at 6:12 PM

    Your way of explanation is very detailed and very easy to understand.Thank you so much for all your efforts. Usually I don’t write comments in any website but couldn’t resist myself by looking at your tutorial. Keep up good work.

    Reply
    • Mukesh Otwani says

      July 25, 2016 at 12:09 PM

      Hey Swapna,

      Thanks a ton 🙂 for the nice feedback. Please let me know if any help required in Selenium from my side.

      Keep learning.

      Reply
  9. suguna says

    April 14, 2016 at 8:58 AM

    Awesome website. Your You tube videos are awesome. I like ur clarity. very neat.

    Reply
    • Mukesh Otwani says

      April 14, 2016 at 2:08 PM

      Thanks Suguna 🙂 Keep visiting and let me know if any help from my side.

      Reply
  10. shubham says

    January 5, 2016 at 7:40 PM

    thanks..I followed your log4j tutorial and able to get logs, but this is additional which i learnt here

    Reply
    • Mukesh Otwani says

      January 6, 2016 at 12:49 AM

      Hi shubham,

      Glad to hear that 🙂 Keep visiting

      Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?