简体   繁体   中英

Cucumber Execution Error Java

Hello every body i am working on a project in which have to implement cucumber with selenium when i run my code following error message is shown I have JDK 7 installed and i am using Jars in image

在此处输入图片说明

java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.<init>(Ljava/util/Properties;[Ljava/lang/String;)V
    at cucumber.runtime.junit.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:32)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:56)
    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:31)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Feature is : Feature: Check addition in Google calculator In order to verify that google calculator work correctly As a user of google I should be able to get correct addition result

Scenario: Addition Given I open google When I enter "2+2" in search textbox Then I should get result as "4"

**Cucumber Steps Class IS :** 


    import java.util.concurrent.TimeUnit;

    import org.junit.Assert;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.By;

        import cucumber.api.java.After;
        import cucumber.api.java.Before;
        import cucumber.api.java.en.Given;
        import cucumber.api.java.en.Then;
        import cucumber.api.java.en.When;

        public class googleCalcStepDefinition {


            protected WebDriver driver;

             @Before
                public void setup() {
                    driver = new FirefoxDriver();
            }

            @Given("^I open google$")
            public void I_open_google() {
                //Set implicit wait of 10 seconds and launch google
                driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
                driver.get("https://www.google.co.in");
            }

            @When("^I enter \"([^\"]*)\" in search textbox$")
            public void I_enter_in_search_textbox(String additionTerms) {
                //Write term in google textbox
                WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
                googleTextBox.sendKeys(additionTerms);

                //Click on searchButton
                WebElement searchButton = driver.findElement(By.id("gbqfb"));
                searchButton.click();
            }

            @Then("^I should get result as \"([^\"]*)\"$")
            public void I_should_get_correct_result(String expectedResult) {
                //Get result from calculator
                WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
                String result = calculatorTextBox.getText();

                //Verify that result of 2+2 is 4
                Assert.assertEquals(result, expectedResult);

                driver.close();
            }

             @After
                public void closeBrowser() {
                    driver.quit();
             }

        }


        **Junit Runner Class is :** 

            import org.junit.runner.RunWith;

            import cucumber.api.junit.Cucumber;

            import cucumber.api.CucumberOptions;;

            @RunWith(Cucumber.class)


 @CucumberOptions(features = {"src/"},glue = {"src/googleCalcStepDefinition.java"})
            public class googleCalcTest {
            }

Fixed This issue just by installing JDK8 64 bit and Eclipse LUNA 64 bit and then using following jars 在此处输入图片说明

Looks like the cucumber.runtime.RuntimeOptions has no constructor which accepts parameters Properties and String. Cucumber libraries you are using do not support this.

Try using something like below.

    import org.junit.runner.RunWith;

    import cucumber.api.junit.Cucumber;

    import cucumber.api.CucumberOptions;;

    @RunWith(Cucumber.class)
    @CucumberOptions(
      features = "<path to feature file>",
      glue = "src/googleCalcStepDefinition.java"
    )
    public class googleCalcTest {
    }

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