javaspring-bootextentreports

How to remove few items from Extent Report


I used Extent Reporting Framework (https://www.extentreports.com/) to generate a nice-looking report in my java / springboot app. There are a few unnecessary items that I would like to remove. Here is my report:-

enter image description here

In the Dashboard view, I want to remove Log Events. How to remove it? Also in the list view, there are 2 items marked. It looks like time and #test-id=1. I want to remove them. I have no idea what are those? Please let me know how to remove them?


Solution

  • I was able to remove/hide any Element from extent report using below code. you can add the below line to your extent report class and locate the element that you want to remove/hide from the report being generated.

    "ExtentSparkReporterObject.config().setJs("document.getElementsByClassName('Class_Name_Of_Element_Needed_to_Be_Removed')[0].style.setProperty('display','none');");"

    My Actual code

    public class ExtentReport {
         static ExtentReports extent;
            final static String filePath = "Report.html";
            static Map<Integer, ExtentTest> extentTestMap = new HashMap<Integer, ExtentTest>();
    
            public synchronized static ExtentReports getReporter() {
                if (extent == null) {
                    ExtentSparkReporter html = new ExtentSparkReporter("Report.html");
                    html.config().setDocumentTitle("Web Automation Test Result");
                    html.config().setReportName("WBHM");
                    html.config().setTheme(Theme.DARK);
                    html.config().enableOfflineMode(true);
                    html.config().thumbnailForBase64();
                    html.config().setTimelineEnabled(false);
                    html.config().setJs("document.getElementsByClassName"
                            + "('col-md-6')[0].style.setProperty('display','none');");          
                    extent = new ExtentReports();
                    extent.attachReporter(html);
                    extent.setSystemInfo("OS", "Windows10");
                    extent.setSystemInfo("Browser", "Chrome");         
                }
                return extent;
            }
            
            public static synchronized ExtentTest getTest() {
                return (ExtentTest) extentTestMap.get((int) (long) (Thread.currentThread().getId()));
            }
    
            public static synchronized ExtentTest startTest(String testName, String desc) {
                ExtentTest test = getReporter().createTest(testName, desc);
                extentTestMap.put((int) (long) (Thread.currentThread().getId()), test);
                return test;
            }
        }