TestNG Report Generation in Selenium WebDriver

Report generation is very important when you are doing the Automation Testing as well as for Manual Testing.

Selenium web driver is used for automating the web-application, but it won't generate any reports.

In this tutorial, you will learn-

Method-1: emailable-report.html

  1. Click on option "emailable-report.html"
  2. Click on option web browser

The output report of testng 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:

Method-2 index.html

  1. Right click on the index.html from the project directory.
  2. Select option open with web browser option. It will display the result in the following order.

The result will look like this:

Method-3 Reporter Class

Along with these 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 is a class present in TestNG. It provides 4 different methods to store log information they are:

  1. Reporter.log(String s);
  2. Reporter.log(String s, Boolean logToStandardOut);
  3. Reporter.log(String s, int level);
  4. Reporter.log(String s, int level, Boolean logToStandardOut);

Example:

Create Two classes such as DemoA and DemoB and write the following code inside the classes.

For Class DemoA;

For Class DemoB:

  1. In the test-output folder, open the emailable-report.html. It will look like:

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.

 

YOU MIGHT LIKE: