Cucumber is not able to find stepDefinition class if its in different package

68 views
Skip to first unread message

Pankaj Tiwari

unread,
Mar 10, 2017, 9:16:37 AM3/10/17
to Cukes

Hi All,

I am creating a project into Selenium+BDD+Cucumber approach where i am facing an issue.

Issue is- if i keep my stepDefinition file in a separate package(for e.g. in "packageB") then cucumber is not able to find it while running the TestRunner class(for e.g: its in "package A") though its working fine if i keep stepdefinition and TestRunner class in same package(either in packageA or packageB).

Kindly see below screenshot for structure. 


Also i have tried option glue, but its also not working.

Whenever i am running my TestRunner class i am getting below error

Running Feature child (scenario)...
Begin scenario run...
Scenario completed...0
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.

1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^User is on home page of the applicaton$")
public void user_is_on_home_page_of_the_applicaton() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^User clicks on Registration link$")
public void user_clicks_on_Registration_link() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^Registration page should be displayed$")
public void registration_page_should_be_displayed() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}



Any help would be appreciated.


-Thanks
Pankaj










Paul Hicks

unread,
Mar 10, 2017, 6:43:20 PM3/10/17
to Cukes
In @CucumberOptions, the glue parameter is a collection of packages, not source directories. If you specify glue = { "org.mycompany.featureA", "org.mycompany.featureB" } then Cucumber will find step definitions in both of those packages.

Pankaj Tiwari

unread,
Mar 16, 2017, 8:07:46 AM3/16/17
to Cukes
Thanks Paul.. its working now.
Reply all
Reply to author
Forward
0 new messages