简体   繁体   中英

Can't run cucumber test - java.lang.NoSuchMethodError: cucumber.runtime.Runtime.<init>

I tried to run cucumber multiple times with the use of Stackoverlow solutions solving this problem for others. It doesn't work for me.

The stacktrace I get running the runnerfile:

java.lang.NoSuchMethodError: cucumber.runtime.Runtime.<init>(Lcucumber/runtime/io/ResourceLoader;Lcucumber/runtime/ClassFinder;Ljava/lang/ClassLoader;Lcucumber/runtime/RuntimeOptions;)V

at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:80)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code -1

My POM file

<groupId>selenium-siebel-new</groupId>
<artifactId>selenium</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>2.43.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>2.43.1</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.0.0.RC14</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>2.43.1</version>
    </dependency>
</dependencies>
</project>

My runner java class:

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src/test/Resources/featurefiles",
    glue = "src/test/java/StepDefs/OpenSummaryPageStepDefs.java"
)
public class ChromeRunner {

private static ChromeDriverService service;

@BeforeClass
public static void createAndStartService() throws IOException {
    service = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File    ("src/main/resources/drivers/chromedriver.exe"))
            .usingAnyFreePort()
            .build();
    service.start();

}
@AfterClass
public static void createAndStopService() {
    service.stop();
}
}

It would be nice if someone has a solution!:)

You should use the same version of Cucumber-java dependencies as the Cucumber-JVM and Cucumber-JUnit dependencies, that is 1.2.5 in POM.xml file. This should solve the problem.

   <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

was facing same issue. for gradle using these two dependencies worked for me.

testCompile 'io.cucumber:cucumber-java:4.2.0'
testCompile 'io.cucumber:cucumber-junit:4.2.0'

I had the same issues as well and i was able to resolved the issue by changing all the info-cukes-cucumber dependencies to io.cucumber dependences

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.3.0</version>
</dependency>

   <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.1</version>
    <scope>test</scope>
</dependency>

Adding dependencies with same version solved my issue with #bobcat too

compile "io.cucumber:cucumber-java:4.2.6"
compile "io.cucumber:cucumber-java8:4.2.6"
compile "io.cucumber:cucumber-guice:4.2.6"
compile "io.cucumber:cucumber-junit:4.2.6"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM