我正在尝试为多个功能创建几个步骤定义类。这是我的项目结构:
.
├── CucumberPOC.iml
└── src
└── test
├── CucumberRunner.java
└── features
├── CheeseStepDefinition.java
├── StepDefinition.java
├── cheese.feature
└── myfeature.feature
它是 CucumberRunner.java 类:
package test;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
format = {" pretty", "json:target/cucumber.js"},
features = { "src/test/" }
)
public class CucumberRunner {
}
有两个步骤定义类。当我运行 cheese.feature 时出现错误:
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java ...
Testing started at 9:26 AM ...
Undefined step: Given I go to google
Undefined step: When I ask for cheese
Undefined step: Then I should see many offers
1 scenario (0 passed)
3 steps (0 passed)
1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^I go to google$")
public void I_go_to_google() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@When("^I ask for cheese$")
public void I_ask_for_cheese() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@Then("^I should see many offers$")
public void I_should_see_many_offers() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
Process finished with exit code 0
但是这些步骤是在 CheeseStepDefinition 中定义的:
package test.features;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class CheeseStepDefinition {
WebDriver driver = null;
@Given("^I go to google$")
public void I_go_to_google() throws Throwable {
driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
}
@When("^I ask for cheese$")
public void I_ask_for_cheese() throws Throwable {
WebElement search = driver.findElement(By.name("q"));
search.sendKeys("cheese");
search.submit();
}
@Then("^I should see many offers$")
public void I_should_see_many_offers() throws Throwable {
System.out.println(driver.getTitle());
driver.close();
}
}
所以我不知道为什么黄瓜java看不到它的步骤定义。我需要做任何其他配置吗?我运行 myfeature.feature 一切正常。
工具信息。
我正在使用这个罐子:
.
├── cucumber-core-1.1.5.jar
├── cucumber-html-0.2.3.jar
├── cucumber-java-1.1.5.jar
├── cucumber-junit-1.1.5.jar
├── cucumber-jvm-deps-1.0.5.jar
├── gherkin-2.12.1.jar
├── hamcrest-all-1.3.jar
├── jsoup-1.8.3.jar
├── junit-4.12.jar
└── selenium-server-standalone-2.47.1.jar
IDE 是 Mac 上的 Intellij 14.1 Community。
如果您需要任何其他信息,请告诉我。