大家好我正在研究一个项目,当我运行我的代码后,必须用硒实现黄瓜 我安装了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)
功能是: 功能:在Google计算器中检查添加内容 为了验证谷歌计算器是否正常工作 作为谷歌的用户 我应该能够得到正确的加法结果
场景:加法 鉴于我打开谷歌 当我在搜索文本框中输入“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 {
}
答案 0 :(得分:3)
修复此问题只需安装JDK8 64位和Eclipse LUNA 64位然后使用以下jar
答案 1 :(得分:0)
看起来cucumber.runtime.RuntimeOptions没有接受参数Properties和String的构造函数。您正在使用的黄瓜库不支持此功能。
尝试使用以下内容。
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 {
}