TestNG Report: In our Earlier post regarding TestNG, we have seen so many powerful features of TestNG. By using all those features, you can create an Automation Framework. But as we discussed the TestNg framework, we have mentioned that multiple factors play an important to create a robust framework.
One of them is Report, which not only informs you that which test case is passed and which is failed, but it also helps you find out the potential bugs. So you should have a clear idea about how you are going to generate the reports using the selenium WebDriver.
Before starting anything about Report, let’s understand:
Why do we need reporting?
When we execute our test cases using any automation tool or Selenium WebDriver, we are trying to perform some operation on the application. As automation testers, we need to test the application by executing the test cases and report the status of the higher management or Development team if we are finding any bugs. That’s why the Report is one of the essential factors of software testing.
Alternative Report: Extent Report Generation In Selenium
Benefits Of Report
- By looking at the report, you can easily find out how many test cases got passed, failed, or skipped.
- Seeing the report, you will come to know the status of the project.
So For Report generation using different types of report as per their organization suitable, like:
- TestNG report
- Extent Report
- Custom Report
But in this post, we are going to learn how to generate a TestNG Report.
TestNG Report
Selenium WebDriver does not have the built-in feature for generating reports. But if we use plugins like TestNG and JUnit, then we can add this functionality to Selenium WebDriver, and we can also get the report.
One we execute our script using TestNG, then TestNg generates a test output folder at the root of the project. WHich has two types of reports on that:
- Detailed Report (index.html)
- Summary Report (emailable-report.html)
Detailed Report:
This report is having all the information like errors, Test Groups, Execution Time, Step by Step Logs, and The TestNG XML File. You can find this report in the output folder, and the file name is index.html file.
Summary report:
This report is not giving all the information, you can say it a trimmed version of a detailed description, and it has information like a number of tests that are “passed/Failed/Skipped.” This report also available inside the output folder, and it is a sharable report which you can share with your stakeholder. You can find this report in the name of emailable-report.html.
Steps to Generate Reports Using TestNG:
- Select The Proper Listener Interface.
- Create the Listener Class
- Create The Test Class
- Create the TestNg.XMl File and Run For Generate the Report.
When we have discussed the listeners, we have mentioned that there are two interfaces are available, By using those we can create the Test Report.
- Commonly Used Interface ITestListener
- Another Method by using the IReporter Interface
In this post, we are going to discuss the widely used interface, which is the ITestListener interface. You can refer to the below listener class, test class, and the Testng.xml File.
Listener Class:
import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult; public class GenerateReport implements ITestListener { @Override public void onStart(ITestContext arg0) { System.out.println("+Begin test: " + arg0.getName()); } @Override public void onTestStart(ITestResult arg0) { System.out.println(" Starting test: " + arg0.getName()); } @Override public void onTestSuccess(ITestResult arg0) { System.out.println(" Test passed: " + arg0.getName()); } @Override public void onTestFailure(ITestResult arg0) { System.out.println(" Test failed: " + arg0.getName()); } @Override public void onTestSkipped(ITestResult arg0) { System.out.println(" Test ignored: " + arg0.getName()); } @Override public void onFinish(ITestContext arg0) { System.out.println("-End test: " + arg0.getName()); } @Override public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) { // TODO Auto-generated method stub } }
Test Class:
Source: Link
Leave a Reply