1

I wrote my first Cucumber program today, and it fails. I wrote a very basic one, a simple scenario and it's step definition. Below is the feature file code and the step definition code.

Step Definiton code:

    import cucumber.api.java.en.When;
    import cucumber.api.java.en.Then;

    public class Testing_Example1 {

           @When("^I am on x page$")
           public void i_am_on_x_page() throws Throwable {

              System.out.println("I am on xPage");

           }

           @Then("^I see that element$")
           public void i_see_that_element() throws Throwable {

               System.out.println("I can see that page");
           }
    }

Feature File Code:

    Feature: Testing
     Scenario: s1
      When I am on x page
      Then I see that element

I have added the system variables as well - The JAVA_HOME and the maven variables as well and linked it to the PATH variable I system variables.

I have added dependencies in the POM file, such as the Cucumber-Java, Cucumber-Junit and for selenium as well and yet my program fails and says the steps are undefined.

Output:

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


    You can implement missing steps with the snippets below:
    @When("^I am on x page$")
    public void i_am_on_x_page() throws Throwable {
   // Write code here that turns the phrase above into concrete     actions
   throw new PendingException();
   }

   @Then("^I see that element$")
   public void i_see_that_element() throws Throwable {
   // Write code here that turns the phrase above into concrete actions    
  throw new PendingException();
  }

   Undefined step: When  I am on x page

   Undefined step: Then  I see that element

   Process finished with exit code 0

I guess it's because my feature file is not getting linked with the step definition file, but I don't understand what is missing that the feature file does not execute properly and scenarios fail. Someone who has knowledge about this, do help.

Thank You!

skate_23
  • 447
  • 1
  • 11
  • 25

2 Answers2

2

I found the solution to this. I just edited the configuration of the feature file - > edit configurations -> Paste the path of the package in which your step definition file is present -> apply.

I just has to link the feature file to the step definition using Glue.

skate_23
  • 447
  • 1
  • 11
  • 25
  • For this code, you do not necessarily need a runner class. You can directly use the glue option in the edit configuration. – skate_23 Jun 08 '18 at 15:20
0

Specify the stepdefintion & feature file details in your cucumber runner class.

@CucumberOptions(
                plugin={"pretty", "html:target/cucumber-html-report","json:target/cucumber-report.json"},
                features = "src/test/resources",
                glue ="com.vg.pw.ui.stepdefinitions",

                )
public class CucumberRunner  {

    ...
}
Balakrishnan
  • 279
  • 2
  • 7