4

I am working on my first feature file/selenium project.

I have created a feature file and runner class.

package cucumberpkg2;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions
(features="Features") 
public class Runner {

}
I have the feature file test.feature
Feature: Login screen

  Scenario Outline: Successful login
    Given User is on Login page
    When User enters valid UserName and Password
    And Clicks the login button
    Then User landed on the home page

But whenever I try to run the TestRunner class as a JUnit test, I get the error:

Test class not found in selected project.

Bitz
  • 27
  • 1
  • 1
  • 9
  • 1
    you also need to specify glue as to where your step definitions resides for the feature file as `glue={"packagename.classname"},` in @CucumberOptions – Kushal Bhalaik May 14 '17 at 18:14
  • @kushal. `glue` option is not mandatory to test the Cucumber project binding. But `glue` is mandatory when you want to test the complete implementation :) Thanks – undetected Selenium May 15 '17 at 10:37
  • @dev, I know that glue isn't mandatory some times but I don't understand your statement :/ – Kushal Bhalaik May 15 '17 at 10:45
  • if you have same structure in resource file as in java for implementations of those featuers you don't need glue statement, otherwise you required it. – Gaurang Shah May 15 '17 at 10:56

2 Answers2

3

Here is the solution to your Question:

  1. As per the current documentation of Cucumber you may require to change the keyword Scenario Outline to Scenario in test.feature file.
  2. Though you mentioned about TestRunner class but your code speaks about Runner class being implemented as public class Runner, be sure which class file are you executing as JUnit test.
  3. You may require to change @CucumberOptions to @Cucumber.Options for previous versions (recent versions work with @CucumberOptions)
  4. Put the following 2 parts in a single line as @Cucumber.Options (features="Features")
  5. As you would be mentioning @Cucumber.Options(features="Features") ensure that your feature file is placed inside Features sub-directory within the Project Directory.
  6. So you will be having, test.feature file within Features sub-directory with the following code:

    Feature: Login screen
        Scenario: Successful login
        Given User is on Login page
        When User enters valid UserName and Password
        And Clicks the login button
        Then User landed on the home page
    
  7. Your Runner class will look like:

    import org.junit.runner.RunWith;
    import cucumber.api.junit.Cucumber;
    @RunWith(Cucumber.class)
    @CucumberOptions(features="Features")
    public class Runner {
    
    }
    
  8. Finally when you will execute Runner class as a JUnit test you will see the following message on your console:

    You can implement missing steps with the snippets below:
    
    @Given("^User is on Login page$")
    public void User_is_on_Login_page() throws Throwable {
        // Express the Regexp above with the code you wish you had
        throw new PendingException();
    }
    
    @When("^User enters valid UserName and Password$")
    public void User_enters_valid_UserName_and_Password() throws Throwable {
        // Express the Regexp above with the code you wish you had
        throw new PendingException();
    }
    
    @When("^Clicks the login button$")
    public void Clicks_the_login_button() throws Throwable {
        // Express the Regexp above with the code you wish you had
        throw new PendingException();
    }
    
    @Then("^User landed on the home page$")
    public void User_landed_on_the_home_page() throws Throwable {
        // Express the Regexp above with the code you wish you had
        throw new PendingException();
    }
    
  9. These warnings can be taken care easily by implementing the glue options to Cucumber.

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

you need to provide full path of the feature file as mentioned below.

@RunWith(Cucumber.class)
@CucumberOptions(
                features = {"src/test/resources/com/gaurang/steps/demo.feature",
                            "src/test/resources/com/gaurang/steps/demo1.feature"
                            }
                )
public class RunAllTest {

}

or if you have too many feature files the best way is to provide tags to feature file and then use those tags to run as mentioned below .

@userRegistrations
Feature: User Registration

RunAllTest.java

@RunWith(Cucumber.class)
@CucumberOptions(tags={"@userRegistrations"})
public class RunAllTest {
}

And you can use multiple tags

Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137