serenity-bdd / serenity-cucumber-starter

A skeleton project for Serenity BDD and Cucumber JVM
Apache License 2.0
180 stars 285 forks source link

Java compatibility with Serenity BDD #82

Open sudheerah opened 2 years ago

sudheerah commented 2 years ago

Hi there,

Do we have any details with regards to java compatibility with SerrenityBDD.

I found this https://github.com/serenity-bdd/serenity-core/#what-is-the-latest-stable-version-i-should-use

However it doesn't specify the java compatibility.

I have project java project with below versions.

Java 17
Gradle 7.4.2
serenityCucumber   : 1.0.29
serenity           : 2.0.90
cucumber        : 4.8.0

But I get below error while running Cucumber tests in IntelliJ. I doubt this is because of Java compatibilty. Because same combination with Java 11 and Maven 3.6.3 runs perfectly

May 12, 2022 7:04:29 PM cucumber.runtime.java.ObjectFactoryLoader loadSingleObjectFactory
WARNING: Loading deprecated ObjectFactory from runtime via reflection: cucumber.runtime.SerenityObjectFactory
May 12, 2022 7:04:29 PM com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1753acfe
java.lang.IllegalStateException: Unable to load cache item
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:79)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.get(LoadingCache.java:34)
......
Caused by: java.lang.ExceptionInInitializerError
    at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:104)
    at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
    at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:77)
    at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache$2.call(LoadingCache.java:54)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:61)
    ... 39 more
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1753acfe
    at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:464)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate(AbstractClassGenerator.java:336)
at cucumber.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:258)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123)
    at cucumber.runtime.Runtime.run(Runtime.java:101)

at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
    ... 35 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
    at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:104)

at cucumber.runner.Runner.runPickle(Runner.java:50)
    ... 8 more

Exception in thread "main" cucumber.runtime.CucumberException: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
    at cucumber.runtime.Runtime.run(Runtime.java:124)
    at io.cucumber.core.cli.Main.run(Main.java:43)
    at io.cucumber.core.cli.Main.main(Main.java:14)
Caused by: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2051)

    ... 2 more
Caused by: java.lang.IllegalStateException: Unable to load cache item
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:79)

... 35 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
    at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:104)

Cucumber Test Class

import org.junit.runner.RunWith;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
    plugin = {"pretty", "html:target/reports/cucumber-html-report",
        "html:target/cucumber-reports/cucumber-pretty",
        "json:target/cucumber.json"},
    tags = {"@test"},
    glue = {"com.abc.stepdefinitions"},
    features = "src/integrationTest/resources/features/")
public class MyServiceCucumberTests {
}

IntelliJ edit config

image

Further in commandline also it gives the same above error.

However I have same setup with Maven and Java 11, it runs fine via both IDE and commandline

sudheerah commented 2 years ago

I managed to run tests via IDE using gradle tasks/ io.cucumber.core.cli.Main. Below are the versions

Java17
Gradle 7.4.2
serenity-cucumber6 - 2.6.0
serenity-rest-assured -  2.6.0

If I use gradle task as below it's giving java.exe error at javaexec in below code

Error: Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Java\jdk-17.0.2\bin\java.exe'' finished with non-zero exit value 1

task cucumber() {
    dependsOn assemble, testClasses

    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty',
                    '--glue', 'xxxxx.stepdefinitions',
                    'src/integrationTest/resources']
        }
    }
    finalizedBy aggregate
}