-1

I had a requirement from my boss where need to create test summary from test report. Therefore, I need to analysis the extent report json file. How to generate the json output file?

Application A Passed
Application B Passed Application C Failed

EDIT: I want to output the extent report in json format

Thanks.

6
  • Please don't down vote my question. I really need help.
    – nicholas
    Nov 22, 2023 at 8:25
  • I didn't downvote, but one reason people do is this question lacks clarity, what you have tried so far. Have you tried anything yet to solve this? If so, does it generate errors? Have you done a Google search? Have you looked at the documentation at extentreports.com on how to implement it? What language/tech stack are you working in?
    – Lee Jensen
    Nov 22, 2023 at 19:51
  • I had did gooogle search regarding this but don't found anything userful. I working on Java.
    – nicholas
    Nov 23, 2023 at 1:34
  • If you can add some examples and what you have tried so far, that would help people understand the problem better and try and come up with a solution. Nov 23, 2023 at 3:19
  • I want to output the extent report in json format. Is it possible? I tried to make the question short and simple.
    – nicholas
    Nov 24, 2023 at 8:06

2 Answers 2

1

A quick Google search and reading the Extent Reports documentation answers this question:

https://www.extentreports.com/docs/versions/4/java/index.html

This page shows all the available reporters Extent has available:

  • ExtentAventReporter
  • ExtentBDDReporter
  • ExtentCardsReporter
  • ExtentEmailReporter
  • ExtentHtmlReporter (deprecated in version-3)
  • ExtentKlovReporter
  • ExtentLoggerReporter
  • ExtentTabularReporter

Some of these are free, built-in options, and some of them you have to pay for.

So, the answer to the question is: no, a JSON report format is not available.

1
  • That said, converting from one format to JSON should be fairly easy, I would think. Nov 28, 2023 at 19:38
0

By default no json report available however we can create new JsonReporter by extending AbstractReporter

package com.sag.core;

import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import com.aventstack.extentreports.ReportAggregates;
import com.aventstack.extentreports.model.Author;
import com.aventstack.extentreports.model.Category;
import com.aventstack.extentreports.model.Device;
import com.aventstack.extentreports.model.Log;
import com.aventstack.extentreports.model.ScreenCapture;
import com.aventstack.extentreports.model.Screencast;
import com.aventstack.extentreports.model.Test;
import com.aventstack.extentreports.reporter.AbstractReporter;
import com.google.gson.Gson;
 
public class JsonReporter extends AbstractReporter {
    private Gson gson = new Gson();
    private String reportFilePath;
 
    public JsonReporter(String reportFilePath) {
        this.reportFilePath = reportFilePath;
    }
 
    @Override
    public void onTestStarted(Test test) {
    }
 
//    @Override
    public void onTestFinished(Test test) {
    }
 
    @Override
    public void start() {
    }
 
    @Override
    public void stop() {
    }
 
    @Override
    public void flush(ReportAggregates reportAggregates) {
        List<Test> testList = reportAggregates.getTestList();
        try (FileWriter writer = new FileWriter(reportFilePath)) {
            gson.toJson(testList, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public String getReporterName() {
        return "Json Reporter";
    }

    @Override
    public void onTestRemoved(Test test) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onNodeStarted(Test node) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onLogAdded(Test test, Log log) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onCategoryAssigned(Test test, Category category) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onAuthorAssigned(Test test, Author author) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onDeviceAssigned(Test test, Device device) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onScreencastAdded(Test test, Screencast screencast) throws IOException {
        // TODO Auto-generated method stub
        
    }
}

Then generate report like this

ExtentReports extent = new ExtentReports();
extent.attachReporter(new JsonReporter("path/to/your/report.json"));

I have used both html and json

 public synchronized static ExtentReports createInstance(String fileName) {
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName + ".html");       
    htmlReporter.config().setTheme(Theme.DARK);
    htmlReporter.config().setDocumentTitle("ExtentReport");
    htmlReporter.config().setReportName("TestReport");
    htmlReporter.config().setEncoding("utf-8");
    htmlReporter.config().setReportName("ExtentReport"); 
    htmlReporter.config().setAutoCreateRelativePathMedia(true);
    extent = new ExtentReports();
    extent.setAnalysisStrategy(AnalysisStrategy.CLASS);
    extent.attachReporter(htmlReporter,new JsonReporter(fileName + ".json"));
    return extent;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.