extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

Program crashing when initializing variables - ExtentReports 5.1.2

Open J-Kiri opened this issue 1 year ago • 0 comments

so i'm trying to apply ExtentReports on a java selenium test application

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class AvantewebsuiteTest {
. . .

  private static ExtentReports extent;
  private static ExtentTest test;

  static{
    try{
      System.out.println("Init Spark");
      ExtentSparkReporter spark = new ExtentSparkReporter("reports/AvanteWebSuiteReport.html");
      System.out.println("Inited Spark");

      spark.config().setReportName("Avante Web Suite - Test Report");
      spark.config().setDocumentTitle("Relatório de Testes");

      System.out.println("Init Extent");
      extent = new ExtentReports();
      System.out.println("Inited Extent");
      extent.attachReporter(spark);

      extent.setSystemInfo("Projeto", "AvanteWebSuite");
      extent.setSystemInfo("Ambiente", "QA");
      extent.setSystemInfo("Usuário", System.getProperty("user.name"));

    } catch (Exception e) {
      e.printStackTrace();
      throw new ExceptionInInitializerError("Failed to initialize ExtentReports: " + e.getMessage());
    }
  }

  public static ExtentReports getExtentReports() {
    return extent;
  }
. . .

The problem is, the program executes that first sout System.out.println("Init Spark"); but as soon as it touches the ExtentSparkReporter spark = new ExtentSparkReporter("reports/AvanteWebSuiteReport.html"); line it gives me this error:

Init Spark
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class testes.avante.testes.AvantewebsuiteTest
        at testes.avante.ui.AvanteGUI.updateBottomPanel(AvanteGUI.java:390)
        at testes.avante.ui.AvanteGUI.access$1200(AvanteGUI.java:22)
        at testes.avante.ui.AvanteGUI$8$1.done(AvanteGUI.java:327)
        at java.desktop/javax.swing.SwingWorker$5.run(SwingWorker.java:750)
        at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:848)
        at java.desktop/sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
        at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:858)
        at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:311)
        at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:243)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: com/aventstack/extentreports/reporter/ExtentSparkReporter [in thread "SwingWorker-pool-1-thread-1"]
        at testes.avante.testes.AvantewebsuiteTest.<clinit>(AvantewebsuiteTest.java:50)
        at testes.avante.ui.AvanteGUI$8$1.doInBackground(AvanteGUI.java:319)
        at testes.avante.ui.AvanteGUI$8$1.doInBackground(AvanteGUI.java:307)
        at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:842)

My mave dependencies are all okay, no conflicts or anything. if i run a minimal setup in the same enviroment like:

package testes.avante.testes;

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

public class ExtentSpark {
  public static void main(String[] args) {
    try {
      System.out.println("Initializing ExtentSparkReporter...");
      ExtentSparkReporter spark = new ExtentSparkReporter("test-report.html");
      System.out.println("ExtentSparkReporter initialized successfully!");

      ExtentReports extent = new ExtentReports();
      extent.attachReporter(spark);

      extent.createTest("Sample Test").pass("This test passed!");
      extent.flush();

      System.out.println("Report generated successfully.");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

everything works perfectly!

i really dont know what to do anymore. if anyone knows what to do, i appreciate the help

J-Kiri avatar Dec 18 '24 16:12 J-Kiri