How to use TestNG Reporter Log in Selenium

On This Page What is TestNG?What are TestNG Reports?

February 28, 2026 · 11 min read · Tool Comparison

How to use TestNG Reporter Log in Selenium

Reports are essential for tracking and analyzing the resultant of exam executions in Selenium. These default HTML reports provide detailed information about trial cases, including their status—whether they passed, failed, or be skipped.

Effective report contemporaries is a critical aspect of both manual and machine-driven examination, as it helps identify issues, reminder progress, and ensure the overall quality of the project.

This tutorial explores how to use TestNG Reports in Selenium to generate elaborate insights and better your testing process.

What is TestNG?

TestNG is an open-source examination automation framework make by Cedric Beust, where ‘ NG ’ stands for Future Generation. TestNG is alike to, however, it is preferred over JUnit, particularly while testing coordinated classes. It is because TestNG proffer comfort of usingmultiple annotations, grouping, dependence, prioritization,andparametrization.

TestNG let QAs to categorize or prioritize the exam example, induce HTML reports, log communique, run trial in parallel, and perform many more actions. These lineament help QA leverage in automation examination.

In order to use TestNG Reporter Log, it is necessary to understand the signification of reporting in a trial.

What are TestNG Reports?

TestNG Reports are auto-generated HTML reports that provide a detailed summary of test case execution when using TestNG with Selenium. These reports help assess the performance and reliability of a project by presenting the status of individual test cases—whether they passed, neglect, or were skipped.

TestNG Reports are essential for both manual and machine-controlled testing as they proffer insights into testing outcomes:

  • They display the total number of passed, failed, and jump test cases.
  • They provide an overview of the undertaking ’ s progress and quality position.

Read More:

Why is Reporting important?

Reports can be insightful and facilitate in deciding the future course of action as it a one-stop source of all the accessible information. With automated report contemporaries framework, it enhances the visualization of test termination for the advance of overall analysis.

However, despite sharing all the major info regarding the tryout, TestNG reports might at times fail to convey the precise root of failure due to inadequate logging. As a effect, you might necessitate to run the whole class to find the problem.

To overcome this job TestNG cater an inbuilt class called the Reporter Class that is used for logging. This tutorial explores how to use the TestNG Reporter Log in to name the cause of a failed test which would ameliorate debugging.

Read More:

What is Reporter Class in TestNG

Reporter Class is an inbuilt class in TestNG, which is available under theorg.testngpackage. This class provides test manner to log dispatches that will be included in the HTML reports generated by TestNG.

Reporter Class is one of the simple ways of generating log information, where the log in the reports can be either stoner-generated or system-generated reports.

TestNG Reporting Class is rather useful as it helps analyze failed tests base on the detailed information from the logarithm. This avoids the need to rerun the entire tryout case. By specify different logarithm at each step, QAs can use this classification when debugging the failures, making debugging easy.

How to Use Reporter Class in TestNG

The Reporter Class in TestNG is a built-in usefulness that simplifies store and managing log data during testing. You can use it alongside theobject.properties queue, which stores both system-generated and user-generated logs.

This approach ensures that relevant log data is systematically organized for easy reference.

Exploiting Reporter Class is one of the leisurely ways to reposit log datum in testing. 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 hereafter when you admittance the story, you can directly consider the log from there sooner than rebroadcast the test cases.

Reporter is a class present in TestNG. 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 grade, Boolean logToStandardOut);

Read More:

How to use TestNG Reporter Log in Selenium

Selenium WebDriver is wide used for test automation of site. However, it lacks reporting of the tests log, hence TestNG is habituate to make report logarithm 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 make:

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

  • emailable-report.html
  • index.html
  • Reporter Class

To understand how TestNG report work using an example, here is a sample Selenium test with TestNG Report.

Also Read:

Step 1:Create a Selenium Test Class identify asEmailReport and TestNG.xmlfile using the following code

package testngpackage; importee org.testng.Assert; import org.testng.SkipException; import org.testng.annotations.Test; public class EmailReport {//To make it pass @ Test public vacancy passTest () {Assert.assertTrue (true);} //To create it fail @ Test public void failTest () {Assert.assertTrue (mistaken);} //To make it skip @ Test public void skipTest () {throw new SkipException (`` Skipping -This method is skipped prove ``);}} & lt;? xml version= '' 1.0 '' encoding= '' UTF-8 ''? & gt; & lt;! DOCTYPE suite SYSTEM `` http: //testng.org/testng-1.0.dtd '' & gt; & lt; suite name= '' testngpackage '' parallel= '' method '' & gt; & lt; test name= '' testngTest '' & gt; & lt; classes & gt; & lt; class name= '' testngpackage.EmailReport '' / & gt; & lt; /classes & gt; & lt; /test & gt; & lt; /suite & gt;

Step 2:Execute the testng.xml file and refreshen the project. You can see the testng.xml file within the project bookletTestNGProjectas seen below.

Also Read:

Step 3: Expand test-outputfolder and you should find a default render TestNG reportemailable-report.html and index.html. Open the study in the browser. Reports will be seen as below:

Emailable Report in TestNG

HTML Index Report in TestNG

How to log messages in reports generate by TestNG Reporter Class

Below is the sample tryout to generate logs expend TestNG Reporter Class in Selenium Test.

Upon fulfil the below examination, the story will experience the following messages logged:

  • Browser Opened
  • Browser Maximized
  • Application Started
  • Application Closed
package testngDemo; importation 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 close '');}}

Let ’ s explore more naturalistic use by creating a class GoogleTest and write the undermentioned code inside the category.

package com.sampletestpackage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; signification org.testng.Reporter; //import org.openqa.selenium.firefox.FirefoxDriver; //import org.openqa.selenium.ie.InternetExplorerDriver; importation org.testng.annotations.Test; public grade GoogleTest {WebDriver driver; @ Test (precedency = 1) public void driverSetup () {// System.setProperty (`` webdriver.gecko.driver '', `` src\\main\\java\\com\\browserdrivers\\geckodriver.exe ''); System.setProperty (`` webdriver.chrome.driver '', `` src\\main\\java\\com\\browserdrivers\\chromedriver.exe ''); //System.setProperty (`` webdriver.ie.driver '', `` src\\main\\java\\com\\browserdrivers\\IEDriverServer.exe ''); driver=new ChromeDriver (); Reporter.log (`` The browser is opened '');} @ Test (priority = 2) public void getURL () {driver.get (`` https: //www.google.com ''); // System.out.println (`` Launching Google situation ''); Reporter.log (`` The Google Site is Launched '');} @ Test (priority = 3) public emptiness getTitle () {String title = driver.getTitle (); System.out.println (rubric); Reporter.log (`` Prints the web page title '');} @ Test (precedency = 4) public void closeBrowser () {driver.close (); //System.out.println (`` Test successfully surpass ''); Reporter.log (`` Close the driver '');}}

Create TestNG.xml by select the above Test Class and Run the test using TestNG.xml. Open the Reports generated.

The Reports are generated as seen below:

Emailable Report with TestNG Reporter Log

HTML Index Report with TestNG Reporter Log

To facilitate further, check out the below list of most commonly used Reporter Logs snippets

/ * * * Log the passed string to the HTML study * @ param s The message to log * / public still void log (String s) {log (s, getCurrentTestResult ());} / * * * Log the passed string to the HTML reports. If logToStandardOut * is true, the twine will also be printed on standard out. * * @ param s The content to log * @ param logToStandardOut Whether to print this string on standard * out too * / public inactive nihility log (String s, boolean logToStandardOut) {log (s, getCurrentTestResult ()); if (logToStandardOut) {System.out.println (s);}} / * * * Log the passed string to the HTML story if the current verbosity * is equal or greater than the one passed in argument * * @ param s The message to log * @ param level The verboseness of this message * / public static nihility log (String s, int level) {if (TestRunner.getVerbose () & gt; = point) {log (s, getCurrentTestResult ());}} / * * * Log the passed string to the HTML story if the current verboseness * is equal or greater than the one passed in parameter. If logToStandardOut * is true, the twine will too be printed on standard out. * * @ param s The message to log * @ param even The verbosity of this message * @ param logToStandardOut Whether to print this string on standard * out too * / public electrostatic void log (String s, int level, boolean logToStandardOut) {if (TestRunner.getVerbose () & gt; = level) {log (s, getCurrentTestResult ()); if (logToStandardOut) {System.out.println (s);}}} // ReporterSample.report () @ Test (dataProvider = `` dp '', timeOut = 10000) public void study (String p) {Reporter.log (`` IN THE REPORTER: `` + p);}} // ReporterLogListener.onTestFailure () @ Override public nothingness onTestFailure (ITestResult result) {Reporter.log (`` Listener: onTestFailure ''); super.onTestFailure (result);} // ReporterLogListener.onTestSuccess () @ Override public void onTestSuccess (ITestResult result) {Reporter.log (`` Listener: onTestSuccess ''); super.onTestSuccess (result);} // ReporterLogListener.onTestSkipped () @ Override public void onTestSkipped (ITestResult result) {Reporter.log (`` Listener: onTestSkipped ''); super.onTestSkipped (result);}}

How to use TestNG Reporter Log for Parallel Tests apply BrowserStack

Testing on a allows the QAs to essay under as opposed to testing on. This helps in have more precise results for the test and identifying bottlenecks in the actual user experience. BrowserStack yield us admission to a of 3500+ existent devices and browser.

Running Selenium tests with TestNG on BrowserStack is quite easy as seen in the step below:

Step 1:Defining a class that contains the method to configure and establish the link with BrowserStack.

software testngDemo; import com.browserstack.local.Local; importation org.json.simple.parser.JSONParser; public class BrowserStackTestNGTest {public WebDriver driver; individual Local l; @ BeforeMethod (alwaysRun=true) @ org.testng.annotations.Parameters (value= {`` config '', `` environment ''}) public void setUp (String config_file, String environment) throws Exception {JSONParser parser = new JSONParser (); JSONObject config = (JSONObject) parser.parse (new FileReader (`` src/test/resources/conf/ '' + config_file)); JSONObject envs = (JSONObject) config.get (`` surround ''); DesiredCapabilities capabilities = new DesiredCapabilities (); Map & lt; String, String & gt; envCapabilities = (Map & lt; String, String & gt;) envs.get (environment); Iterator it = envCapabilities.entrySet () .iterator (); while (it.hasNext ()) {Map.Entry pair = (Map.Entry) it.next (); capabilities.setCapability (pair.getKey () .toString (), pair.getValue () .toString ());} Map & lt; String, String & gt; commonCapabilities = (Map & lt; String, String & gt;) config.get (`` capableness ''); it = commonCapabilities.entrySet () .iterator (); while (it.hasNext ()) {Map.Entry pair = (Map.Entry) it.next (); if (capabilities.getCapability (pair.getKey () .toString ()) == null) {capabilities.setCapability (pair.getKey () .toString (), pair.getValue () .toString ());}} String username = System.getenv (`` BROWSERSTACK_USERNAME ''); if (username == null) {username = (String) config.get (`` user '');} String accessKey = System.getenv (`` BROWSERSTACK_ACCESS_KEY ''); if (accessKey == cypher) {accessKey = (String) config.get (`` key '');} String app = System.getenv (`` BROWSERSTACK_APP_ID ''); if (app! = null & amp; & amp;! app.isEmpty ()) {capabilities.setCapability (`` app '', app);} if (capabilities.getCapability (`` browserstack.local '')! = void & amp; & amp; capabilities.getCapability (`` browserstack.local '') == `` true '') {l = new Local (); Map & lt; String, String & gt; options = new HashMap & lt; String, String & gt; (); options.put (`` key '', accessKey); l.start (options);} driver = new RemoteWebDriver (new URL (`` https: // '' +username+ '': '' +accessKey+ '' @ '' +config.get (`` server '') + '' /wd/hub ''), capabilities);} @ AfterMethod (alwaysRun=true) public void tearDown () throws Exception {driver.quit (); if (l! = null) l.stop ();}}

Read More:

Step 2: Creating single.conf.jsonfor configuring your BrowserStack exploiter credentials utilize the code snip below

{'' server '': `` hub-cloud.browserstack.com '', '' user '': `` YOUR_USERNAME '', '' key '': `` YOUR_ACCESS_KEY '', '' potentiality '': {'' build '': `` testng-browserstack '', '' gens '': `` single_test '', '' browserstack.debug '': true}, '' environment '': {'' chrome '': {'' browser '': `` chrome ''}}}

Step 3: Creating single.conf.xmlfile for configuring TestNG using the code snippet below

& lt;? xml version= '' 1.0 '' encoding= '' UTF-8 ''? & gt; & lt;! DOCTYPE suite SYSTEM `` http: //testng.org/testng-1.0.dtd '' & gt; & lt; suite name= '' Single '' & gt; & lt; test name= '' SingleTest '' & gt; & lt; argument name= '' config '' value= '' single.conf.json '' / & gt; & lt; argument name= '' environs '' value= '' chrome '' / & gt; & lt; classes & gt; & lt; class name= '' com.browserstack.SingleTest '' / & gt; & lt; /classes & gt; & lt; /test & gt; & lt; /suite & gt;

BrowserStack cater an integral REST API to pierce and modernise facts about our exam, which can be used to label the exam as passing or fail.

Tag the tests as passing or fail ground on the assertions in the TestNG test instance using the code below.

// Method to tag examination as pass / fail on BrowserStack public static nullity grade () throws URISyntaxException, UnsupportedEncodingException, IOException {URI uri = new URI (`` https: //YOUR_USERNAME: YOUR_ACCESS_KEY @ api.browserstack.com/automate/sessions/ & lt; session-id & gt; .json ''); HttpPut putRequest = new HttpPut (uri); ArrayList & lt; NameValuePair & gt; nameValuePairs = new ArrayList & lt; NameValuePair & gt; (); nameValuePairs.add ((new BasicNameValuePair (`` status '', `` completed ''))); nameValuePairs.add ((new BasicNameValuePair (`` reason '', `` ''))); putRequest.setEntity (new UrlEncodedFormEntity (nameValuePairs)); HttpClientBuilder.create () .build () .execute (putRequest);}

Talk to an Expert

No matter the software, Selenium WebDriver exam must be execute on real device and browser. Remember that is a major concern for every developer and quizzer. Every website has to work seamlessly on multiple device-browser-OS combination. With being used to entree the internet globally, all package has to be optimized for different shape, viewports, and screen declaration.

In this state, no emulator or simulator can replicate. Software necessitate to be tested on existent devices so that they can work in real-world circumstances such as a low battery, incoming calls, weak network strength, and so on. If an in-house lab is not approachable, opt for a that offers real devices.

Conclusion

BrowserStack ’ s pass 3500+ real device and browsers for automated testing. That means users can run tests on multiple existent devices and browser by simply signing up, logging in, and take the required combination. Testers can besides deport on 30+ real browser versions across Windows and macOS. Detect bugs before users do by test software in real user conditions with BrowserStack.

Try BrowserStack for Free

Tags
82,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free