How to setup multiples step definitions for Cucumber Java features on Intellij -
i trying create several step definitions classes several features. project structure:
. ├── cucumberpoc.iml └── src └── test ├── cucumberrunner.java └── features ├── cheesestepdefinition.java ├── stepdefinition.java ├── cheese.feature └── myfeature.feature
it cucumberrunner.java class:
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 { }
there 2 step definitions classes. when run cheese.feature got error:
/library/java/javavirtualmachines/jdk1.8.0_60.jdk/contents/home/bin/java ... testing started @ 9:26 ... undefined step: given go google undefined step: when ask cheese undefined step: should see many offers 1 scenario (0 passed) 3 steps (0 passed) 1 scenarios (1 undefined) 3 steps (3 undefined) 0m0.000s can implement missing steps snippets below: @given("^i go google$") public void i_go_to_google() throws throwable { // express regexp above code wish had throw new pendingexception(); } @when("^i ask cheese$") public void i_ask_for_cheese() throws throwable { // express regexp above code wish had throw new pendingexception(); } @then("^i should see many offers$") public void i_should_see_many_offers() throws throwable { // express regexp above code wish had throw new pendingexception(); } process finished exit code 0
but steps defined in 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 google$") public void i_go_to_google() throws throwable { driver = new htmlunitdriver(); driver.get("http://www.google.com"); } @when("^i ask 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(); } }
so don't know why cucumber java doesn't see step definition. need other configuration? run myfeature.feature , ok.
tools info.
i using jars:
. ├── 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
the ide intellij 14.1 community, on mac.
if need other information, let me know.
you have need define in cucumber options "glue" options.
in runner define glue , features are. >>> glue stepdefinitions , feature features.
in case have stepdefinition in same place features, have tell runner.
in case should be
@cucumberoptions( format = {" pretty", "json:target/cucumber.js"}, features = { "src/test/"}, glue ={ "src/test/" })
regards,
Comments
Post a Comment