简体   繁体   中英

Error when running Cucumber Junit test :Intializationerror

I'm trying to run cucumber test,but i'm getting the following exception. I used those jars with their versions

在此处输入图片说明

And this is my project :

在此处输入图片说明

And this is testRunner class code :

    package cucumberTest;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "Feature"
        ,glue={"stepDefinition"}
        )

        public class TestRunner {

        }

In the logIn.feature file :

Feature: Login Action Test

Scenario: Successful Login with Valid Credentials Given User is on Home Page When User Navigate to LogIn Page And User enters UserName and Password Then Message displayed Login Successfully

Scenario: Successful LogOut When User LogOut from the Application Then Message displayed LogOut Successfully

According to this , cucumber-java-1.2.5 requires gherkin-2.12.2, while I was providing gherkin-4.1.13

So I downloaded version 2.12.2 from here , removed version 4.1.13 and it worked for me (I did a clean to the project).

I'm new and still learning. I had a similar 'cucumber runner initialization error' message:

java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptionsFactory.<init>(Ljava/lang/Class;[Ljava/lang/Class;)V
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    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:26)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

Referenced Libraries <= My Jars when I was having an error. I then replaced my cucumber-junit-1.1.5.jar with cucumber-junit-1.2.2.jar and the error message is now resolved. I can now run my cucumber junit test. I started with the latest jars but they seems to have issues. I then tried several different combination. I read 'rule of thumb' that the three jars (-core, -java and -junit) need to be of same version. Only then I was able to run my feature files and junit tests.

My current working jars are:

gherkin-2.12.2
cucumber-core-1.2.2
cucumber-java-1.2.2
cucumber-junit-1.2.2
cucumber-html-0.2.3
cucumber-jvm-deps-1.0.3
hamcrest-all-1.3
junit-4.11
selenium-server-standalone-3.13.0

I hope this helps.

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