Klov – ExtentReports | Test Automation Reporting

Hello everybody, today I am going to talk about Klov – ExtentReports reporting library by ExtentReports. As you may already know, ExtentReport provides great visual reporting to your Selenium tests. We talked about it in this article (http://www.swtestacademy.com/extentreports-testng/)  You might need to read this article to fully understand this article as I am not going into deep with TestNG and other configurations.

Extent Report team extended this library for historical reporting. Right now Extent Report is a web application using MongoDB and Spring Framework. Right now you can track your builds, their execution results aligned with it by using the web application.

I used Selenium with TestNG. So I will use TestNG listener to create my report. You may customize it for JUnit also. Here is the basic instruction to get started.

Installing Mongo DB and Run It

Installing is a straightforward process. I am using MacOS so my instruction might change in other OS.

Run Brew update and brew install mongodb command on your terminal. MongoDB is installed.

Right now, we need to run it. Type mkdir -p /data/db in terminal. By this way, you’ll create a folder for mongoDB to store its DB. In case you get a warning message mkdir: /data/db: Permission denied , just use sudo command as sudo mkdir -p /data/db.

Finally, run mongod command. You might once again receive an exception about writing, reading exceptions to the previously created folder. Mongod command tries to write and read from data/db folder by default. In case you have this exception, add sudo command as sudo mongod

For Windows installation of MongoDB please click here.

Run Your Klov – ExtentReports Application

Download your Klov-x-x-x.jar file from http://extentreports.com/community/ page. You’ll see Klov Download link at the bottom of the page. There are 2 files that are important to you:

  1. klov-x-x.jar file
  2. application.properties file.

You can run klov in the terminal with java -jar klov-x-x.jar command. You need to provide the right version.  In case you get an exception about port binding, go to application.properties file and change server.port value with an unbind port. (Note: On Windows please try to run java -jar klov-x-x.jar on the command prompt.)

Open Klov – ExtentReports Application

Go to http://localhost:portNo and if you see the welcome page. Everything is ready for Klov – Extentreports.

Modifying Your Selenium Test

First of all, there’s no need to change your test code. All you need to do is add a test listener into your project and Klov reporting basic Java code.

Test Base Code

I have added the basic code into my BeforeClass Annotation.

@BeforeClass
public void setup () {
   driver = new ChromeDriver();
   driver.manage().window().maximize();

   driver.navigate().to("http://www.swtestacademy.com");
   KlovReporter klovReporter = new KlovReporter();

   klovReporter.initMongoDbConnection("localhost", 27017);

   klovReporter.setProjectName("SWTestAcademy");

   klovReporter.setReportName("2.0");

   klovReporter.setKlovUrl("http://localhost");

   extentReports = new ExtentReports();
   extentReports.attachReporter(klovReporter);
  • Create a KlovReporter object.
  • Define MongoDB connection
  • Give a project name to our test project
  • Define the build no as report name.
  • Set klov server URL
  • Finally, create an ExtentReports object and bind it to KlovReport object.

By doing so Klov will create a project with the given name. In case it exists, Klov will use the previously created project and store the results into it.

Test Listener Code

Test Listener base code is below. I create an ExtentTest object in the onTestStart method. So Klov – Extentreports starts to log this test.

@Override
public void onTestStart(ITestResult iTestResult) {
   System.out.println("I am in onTestStart method " +  getTestMethodName(iTestResult) + " start");
   test = extentReports.createTest(getTestMethodName(iTestResult) + " started");

}

Then after onTestSuccess, onTestFailute and onTestSkipped methods, I mark my test as pass, fail or skip.

@Override
public void onTestSuccess(ITestResult iTestResult) {
   System.out.println("I am in onTestSuccess method " +  getTestMethodName(iTestResult) + " succeed");
   test.pass("Test passed");
}

@Override
public void onTestFailure(ITestResult iTestResult) {
   System.out.println("I am in onTestFailure method " +  getTestMethodName(iTestResult) + " failed");
   test.fail("Test Failed");
}

@Override
public void onTestSkipped(ITestResult iTestResult) {
   System.out.println("I am in onTestSkipped method "+  getTestMethodName(iTestResult) + " skipped");
   test.skip("Test Skipped");
}

Now run your tests and see the results like a charm in Klov Web Dashboard. You can check failures in historical view in timeline chart. You’ll see how many time you executed those tests and their build execution info.

Then you can check which tests are failing the most.

Finally, you can track the status with bar charts.

Sample Project Code is herehttps://github.com/swtestacademy/klov-extentreports-example

Happy testing!
Canberk Akduygu

9 thoughts on “Klov – ExtentReports | Test Automation Reporting”

  1. Can someone tell me what the Build performance metric in the report is about ?. i see for my every build the values are abount “0.015xxxxxx”. What metric is this ? definitely doesnt look like test excution duration as it’s in minutes in my case

    Reply
  2. Hi Canberk Akduygu,

    Kindly help me, I am using TestNg, Klov & (mongo db)-using Cucumber (BDD), I am calling from testNg to runner class-its printing method name as feature which is in this Runner class rather than method names of StepDefinition.

    public class RunCucumberFeatures extends Hooks {
    private TestNGCucumberRunner testNGCucumberRunner;
    @BeforeClass(alwaysRun = true)
    public void setUpClass() {
    System.out.println(“Cucumber OTP Class Before”);
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());

    }

    @Test(groups = “cucumber”, description = “Runs Registration Feature”, dataProvider = “features”)
    public void feature(CucumberFeatureWrapper cucumberFeature) {
    System.out.println(“Cucumber OTP Class Inside OTP”);
    System.out.println(cucumberFeature.getCucumberFeature());
    testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());

    }

    @DataProvider
    public Object[][] features() {
    System.out.println(“Data Provider test Class”);
    return testNGCucumberRunner.provideFeatures();

    }

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.