top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

How to use TestNG Reporter

Test reports are critical to a testing process, this blog provides a step-by-step guide on using TestNG Reporter and different reports in testNG.


  • Why is Reporting important?

Report generation is very important when you are doing the Automation Testing as well as for Manual Testing. By looking at the result, you can easily identify how many test cases are passed, failed and skipped. it enhances the visualization of test results for the betterment of overall analysis.

Selenium WebDriver is widely used for test automation of websites. However, it lacks reporting of the tests logs, hence TestNG is used to create report logs that would help identify and debug failed tests. TestNG induces dereliction of HTML reports once the test cases are executed.

Following TestNG Reports can be created:


  • emailable-report.html

  • index.html

  • Reporter Class

Step 1: Create a Selenium Test Class named as EmailReport or any name of your choice.



Step 2: Execute the testng.xml file and refresh the project. Expand test-output folder and you should find a default generated TestNG report emailable-report.html and index.html. Open the report in the browser. Reports will be seen as below:




Emailable Report in TestNG



HTML Index Report in TestNG

Reporter Class in TestNG:

Reporter class is an inbuilt class in TestNG. It helps in depositing the logs inside the reports, which are user-generated or system-generated so that in the future when you access the report, you can directly view the logs from there rather than rerunning the test cases.

It has four different approaches to storing the log information:

  • Reporter.log( String s);

  • Reporter.log ( String s, Boolean logToStandardOut);

  • Reporter.log ( String s, int level);

  • Reporter.log ( String s, int level, Boolean logToStandardOut);

Now, let’s go through each one of these TestNG Reporter Log syntaxes in detail.


1. Reporter.log(String s);

This method logs the string passed into your HTML Report.

Parameters:

S – The message to be logged

Example:

Reporter.log("Logging into Browser");


2. Reporter.log(String s, Boolean logToStandardOut);

This method logs the string passed into your HTML Report. Additionally, it also prints the same message on your console if logToStandardOut is set to TRUE.

Parameters:

S – The message to be logged

logToStandardOut – Print the message on standard output

Example:

Reporter.log("Logging into Browser", true);


3. Reporter.log(String s, int level);

This method logs the string passed into your HTML Report if the current verbosity equals or is greater than the one passed in the parameter.

Parameters:

S – The message to be logged

level – The verbosity of the message to be logged

Example:

Reporter.log("Logging into Browser", 2);


What is Verbosity Level in TestNG?


The Verbose Level in TestNG is used to define the amount of logging performed on the console. The verbosity level ranges from 0 to 10, where 10 is the most detailed logging level whereas 0 means minimal logging.

You can set the verbosity level in your testng.xml. Below is a sample snippet from the tesng.xml, which indicates how to do the same.

<suite thread-count="2" name="TestNGReporterTest" parallel="classes" verbose="10">


4. Reporter.log(String s, int level, Boolean logToStandardOut);

This method logs the string passed into your HTML Report if the current verbosity equals or is greater than the one passed in the parameter. Additionally, it will print the message onto the console if logToStandardOut is set to TRUE.

Parameters:

S – The message to be logged

level – The verbosity of the message to be logged

logToStandardOut – Whether to print the message on standard output as well

Example,

Reporter.log("Logging into Selenium Playground", 2, true);


Below is the sample test to generate logs using TestNG Reporter Class in Selenium Test.



HTML Index Report with TestNG Reporter Log

Happy Learning!!


188 views0 comments

Recent Posts

See All
bottom of page