Reporting in TestNG – User friendly Tech help

Why we need Reporting?
nWhen we are using Selenium or any other automation tool (say UFT), we are replicating user interactions on the AUT(Application under Test).But our aim is not only to test AUT, but to comprehend the result of test execution, points of failure(Bug), and reason of the failure, and reporting it to development team or higher management. Thus reporting is the most crucial aspect of our test execution, which helps in keeping an eye on the execution flow or for debugging in case of failures.
nRead more on Reporting in UFT
n
nTestNG Reporting:- 
nWe have already seen the default reporting in TestNG using index.html and emailable-report.html.Further to this we can add our own user friendly logs in the HMTL reporting by using Reporter class. We can also create costume reporting in TestNG using ReportNG
n
nSyntax:-

n

n

n

n

n

n

n

n

Reporter.Log as an overloaded method

n

Reporter.Log(“Message”, logToStandardOut)
n
nMessage:-String message for output
nlogToStandardOut:- is a Boolean value, which signifies whether to print the “Message” on console too. Incase it is set “False”, message won’t be shown in console output of Eclipse.
n
nCode:-
n

n

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class ReporterInTestNG { @Test
public void maximize(){
WebDriver driver = new FirefoxDriver();
//Variable to disable/Enable Reporter results in Console
boolean bolConsole;
bolConsole=true;
Reporter.log("Driver Object Created!",bolConsole);
driver.get("http://www.ufthelp.com/p/selenium.html");
Reporter.log("URL is Launched!",bolConsole);
//Using "Maximize" command
driver.manage().window().maximize();
Reporter.log("Maximized browser using 'Maximize' command!",bolConsole);
//Resize window
driver.manage().window().setSize(new Dimension(200, 100));
Reporter.log("Rezized window using setSize!",bolConsole);
//Quit Browser
//driver.quit(); }}

n

Output:-
n
nConsole(bolconsole = true)
n

n

n

n

n

n

n

n

n

Console output in TestNg

n

 index.html, (inside test-output folder)

n

n

n

n

n

n

n

n

HTML Results in TestNG

n

Note:- Incase we are setting (bolconsole=false) in our code, console will not display the “Reporter” messages.
n
Key points:-
nWe can implement our own costume reporting in TestNG by implementing:-

n

n

How to open HTML reports in TestNG

Was this article helpful?
YesNo

Similar Posts