TestNG Reports Generation in Selenium: How to Generate?
What are TestNG Reports?
TestNG Reports are the default HTML reports which are generated once the test cases are executed using TestNG. These reports help you to identify the information about test cases and the status of a project. TestNG reports in Selenium have three methods passTest, failTest, and skipTest to check the data about test cases.
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.
- By looking at the report, you will come to know what the status of the project is.
Selenium web driver is used for automating the web-application, but it won't generate any reports.
- The TestNG will generate the default report.
- When you execute testng.xml file, and refresh the project. You will get test-output folder in that folder for reporting in TestNG.
- Right click on the emailable-report.html and select the option. Open with the web browser.
In this tutorial, you will learn-
How to generate reports in Selenium
- Click on option "emailable-report.html"
- Click on option web browser
The output reports in TestNG reporting will look like below if both the classes are passed:
Consider the scenario in where you are intentionally failing the test case i.e. DemoB class. Then convert both the classes into testng.xml suite file and run it. Then the result will look like this. It will show the failed test cases.
This is result for DemoB class:
Similarly, result for the Class DemoA will look like this:
- Right click on the index.html from the project directory.
- Select option open with web browser option. It will display the result in the following order.
The result will look like this:
Along with these TestNG report generated methods, you can use object.properties file to store the system generated logs as well as user generated logs. But one of the simplest ways to store log information in testing is using Reporter Class.
Reporter.log in Selenium is a class present in TestNG for Selenium reporting. It provides 4 different methods to store log information they are:
- Reporter.log(String s);
- Reporter.log(String s, Boolean logToStandardOut);
- Reporter.log(String s, int level);
- Reporter.log(String s, int level, Boolean logToStandardOut);
Create Two classes such as DemoA and DemoB and write the following code inside the classes.
For Class DemoA;
- The Code for DemoA is already explained above. Here you are using log method of Reporter class. (For implementing a reporting class, the class has to implement an org.testng.IReporter interface).
- The log method is a static method of Reporter class. So you are accessing that method through the Reporter class.
- The log method is used to store log information that is written inside the program. By looking at the log information, you will easily come to know where exactly the execution of the program is stopped.
For Class DemoB:
- Now, Create testng.xml file by selecting these two classes and
- Select run as and
- Click on the convert to testng.
- Then run this testng.xml file by selecting run as and select testng suite.
- Then refresh the project open the test-output folder.
Similarly, you will have an Output for Demo B project as well.
2. In test-output folder open the index.html. It will look like:
Click on reporter output. It will open logging info whatever written in the test methods.
Click on the Times. It will going to show how much time it took to run the test method present in class using TestNG reporting tools.