I'm having an annoying problem with Selenium and ExtentReports.
@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; } . . .
This is the place in my code where I initialize ExtentReports things and it's right at the beginning of the class. The problem is, the program executes that first sout:
System.out.println("Init Spark");
but as soon as it touches the line:
ExtentSparkReporter spark = new ExtentSparkReporter("reports/AvanteWebSuiteReport.html");
the program stops and returns 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 Maven dependencies are all okay, no conflicts or anything. If I run a minimal setup in the same environment like this:
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 already updated all the dependencies, tried an older version of ExtentReports, tried calling ExtentReports from a separate class and everything.
My main file doesn't have a main method:
public static void main(String[] args)
But I really don't believe that's the problem.
My program starts with a GUI menu on another class and then it calls this file - but that can't be the problem, right?