Saturday 29 June 2019

Extent Report: Hello World Application


In this post, I am going to show you, how to generate basic html report using Extent API.

Step 1: Create an instance of 'ExtentHtmlReporter'
private static final String FILE_NAME = "myReports.html";
private static final ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(FILE_NAME);

Above statements define an instance of 'ExtentHtmlReporter'. All the reports are written to ‘myReports.html.

Step 2: Create an instance of ExtentReports and attach htmlReporter to it.
private static final ExtentReports extentReports = new ExtentReports();
extentReports.attachReporter(htmlReporter);

Step 3: Create some information and write it to the extentReports.
extentReports.createTest("First Test Case").pass("First Test Case is Passed");
extentReports.createTest("Second Test Case").fail("Second Test Case is Failed");

Flush the report.
extentReports.flush();

Find the below working application.

Test.java
package com.sample.app;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

public class Test {

 private static final String FILE_NAME = "myReports.html";

 private static final ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(FILE_NAME);

 private static final ExtentReports extentReports = new ExtentReports();

 static {
  extentReports.attachReporter(htmlReporter);
 }

 public static void passTheTestCase() {
  extentReports.createTest("First Test Case").pass("First Test Case is Passed");
  extentReports.flush();
 }

 public static void failTheTestCase() {
  extentReports.createTest("Second Test Case").fail("Second Test Case is Failed");
  extentReports.flush();
 }

 public static void main(String args[]) {
  passTheTestCase();
  failTheTestCase();
 }
}

Run the application Test.java, reports are written to ‘myReports.html’ file.


Open myReports.html file, you can able to see below kind of screen.

Key things to note.
1.   Specifies the time of report generatiom
2.   Version of the Extent API used
3.   Specifies how many test are passed and failed
4.   Each test case displayed in this section
5.   Whenever you click any test in section 4, the test case is detailed here.

Filter out the pas, failed test cases
Click on ‘Status’ button, you can filter out the test cases based on their status like pass, fail etc.,

No comments:

Post a Comment