0

大家好,我正在从事一个项目,当我运行我的代码时,我必须使用 selenium 实现黄瓜,然后显示错误消息我已经安装了 JDK 7,并且我正在使用图像中的 Jars

在此处输入图像描述

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)

功能是: 功能:检查谷歌计算器中的加法为了验证谷歌计算器是否正常工作作为谷歌的用户,我应该能够得到正确的加法结果

场景:加法给定我打开谷歌当我在搜索文本框中输入“2 + 2”然后我应该得到结果为“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 {
            }
4

2 回答 2

3

只需安装 JDK8 64 位和 Eclipse LUNA 64 位,然后使用以下 jar 即可解决此问题 在此处输入图像描述

于 2015-05-20T09:25:23.967 回答
0

看起来 cucumber.runtime.RuntimeOptions 没有接受参数属性和字符串的构造函数。您正在使用的 Cucumber 库不支持此功能。

尝试使用类似下面的东西。

    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 {
    }
于 2015-05-20T06:54:29.713 回答