Reporter Class in TestNG
1. What Is the Reporter Class in TestNG?
The org.testng.Reporter class provides static methods to log custom messages during test execution. These messages are collected by TestNG and surfaced in both the HTML reports (including the emailable report) and, optionally, in the console.
2. Syntax for Using Reporter
import org.testng.Reporter;
public class MyTest {
@Test
public void exampleTest() {
Reporter.log("This is a custom log message");
// … test steps …
Reporter.log("Another message with newline<br/>", true);
}
}
Reporter.log(String message)
Adds message to the report only.
Reporter.log(String message, boolean toConsole)
If toConsole == true, also prints message to System.out.
3. Logging Messages in Reports
Use Reporter.log(…) anywhere in your test or configuration methods:
@Test
public void loginTest() {
Reporter.log("→ Navigating to login page", true);
loginPage.open();
Reporter.log("→ Entering credentials", false);
loginPage.enterUsername("alice");
loginPage.enterPassword("secret");
loginPage.submit();
Reporter.log("→ Submitted login form", true);
Assert.assertTrue(dashboardPage.isVisible());
}
Messages accumulate under the “Reporter output” column/cell for each test in the HTML reports.
4. Viewing Logged Messages in the Emailable Report
Run your tests with TestNG.
Open test-output/emailable-report.html in your project.
In the table listing your test methods, expand the “Reporter output” section for each test to see all Reporter.log entries.
5. Viewing Reporter Logs in the Console
By default, Reporter.log(msg) does not print to console.
To echo a message to the console, pass true as the second argument:
Reporter.log(“This appears in both report and console”, true);
You’ll then see these lines interleaved with your test’s System.out output in Eclipse/IntelliJ’s console or your CI logs.
With the Reporter API you can insert rich, step-by-step logging into your TestNG reports—making it easy to trace what happened inside each test when you review the results.