telekom / testerra

Testerra is an integrated framework for automating tests for (web) applications.
https://docs.testerra.io/
Apache License 2.0
27 stars 15 forks source link

Unable to initialize modules when run built fat jar #421

Closed erickubenka closed 6 months ago

erickubenka commented 6 months ago

Describe the bug For an automation project that should continuously run a UI scraper, I decided to go for a public static void main function inside a Main class of my project. Then go for a gradle build including all dependencies to have a fat jar availbale to run the application standalone. When executing the jar file the IoC kicks in when initializing Testerra, but somehow modules are tried to instantiated that are not part of the TesterraListener.DEFAULT_PACKAGES list ("eu.tsystems.mms.tic", "io.testerra") but still extends the com.google.inject.AbstractModule class.

To Reproduce Steps to reproduce the behavior:

  1. Clone latest testerra-skeleton project
  2. Create a simple class Main in src/main/java (content shown below)
  3. Add a Gradle build step fo building a fat jar inside build.gradle (content shown below)
  4. Run gradle jar
  5. Run the built jar file cd builds/lib && java -jar testerra-skeletons-2-SNAPSHOT.jar

content of src/main/java/Main.java

import eu.tsystems.mms.tic.testframework.common.PropertyManagerProvider;
import eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider;

public class Main implements WebDriverManagerProvider, PropertyManagerProvider {

    public static void main(String[] args) {
        System.out.println("Hello, World!");
        PROPERTY_MANAGER.setSystemProperty("tt.browser", "chrome");
        WEB_DRIVER_MANAGER.getWebDriver();
    }
}

content of build.gradle

jar {
    manifest {
        attributes 'Main-Class': 'Main'
        attributes 'Multi-Release': 'true'
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }

    exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "guice-4.2.2-no_aop.jar")
    duplicatesStrategy = DuplicatesStrategy.WARN
}

Expected behavior Application starts, Testerra boots successfully, WebDriverManager ensures that a browser will be opened.

Actual behavior

25.04.2024 08:54:59.231 [main][ERROR]: common.Testerra - Unable to initialize modules
java.lang.NoSuchMethodException: com.google.inject.util.Modules$OverrideModule.<init>()
        at java.lang.Class.getConstructor0(Class.java:3585) ~[?:?]
        at java.lang.Class.getConstructor(Class.java:2271) ~[?:?]
        at eu.tsystems.mms.tic.testframework.common.Testerra.initIoc(Testerra.java:182) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at eu.tsystems.mms.tic.testframework.common.Testerra.<clinit>(Testerra.java:141) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider.<clinit>(WebDriverManagerProvider.java:32) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at Main.main(Main.java:7) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider.<clinit>(WebDriverManagerProvider.java:32)
        at Main.main(Main.java:7)
Caused by: java.lang.NullPointerException: module cannot be null.
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:921)
        at com.google.inject.spi.ModuleSource.<init>(ModuleSource.java:70)
        at com.google.inject.spi.ModuleSource.<init>(ModuleSource.java:56)
        at com.google.inject.spi.Elements$RecordingBinder.getModuleSource(Elements.java:522)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:330)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
        at com.google.inject.Guice.createInjector(Guice.java:87)
        at com.google.inject.Guice.createInjector(Guice.java:69)
        at com.google.inject.Guice.createInjector(Guice.java:59)
        at eu.tsystems.mms.tic.testframework.common.Testerra.initIoc(Testerra.java:199)
        at eu.tsystems.mms.tic.testframework.common.Testerra.<clinit>(Testerra.java:141)
        ... 2 more

Screenshots No screenshots applicable

Test No test possible, due to run of the built fat jar.

Environment(please complete the following information):

Additional context I will provide a pull request adressing this issue.