Cucumber test not working

I am working on my first project file / selenium.

I created a properties file and a 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 {

}
      

Run codeHide result


I have a 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:

The test class was not found in the selected project.

+3


source to share


2 answers


you need to provide the full path to the functions file as 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 function files, the best way is to provide tags to the functions file and then use those tags to run as below.

@userRegistrations
Feature: User Registration

      



RunAllTest.java

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

      

And you can use multiple tags

0


source


Here is the solution to your question:

  • As per the current Cucumber documentation, you may need to change the keyword Scenario Outline

    to Scenario

    to test.feature

    file.
  • Although you mentioned a class TestRunner

    , but your code is talking about a class Runner

    being implemented as public class Runner

    , make sure the class file you are executing as JUnit test

    .
  • You may need to change @CucumberOptions

    to @Cucumber.Options

    for previous versions (latest versions work with @CucumberOptions

    )
  • Put the next two parts on one line as @Cucumber.Options (features="Features")

  • As you might mention @Cucumber.Options(features="Features")

    , make sure your function file is placed inside a subdirectory of your Features

    project directory.
  • So, you will have a test.feature

    file in a subdirectory Features

    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
    
          

  • Your class Runner

    will look like this:

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

  • Finally, when you execute the class Runner

    as a JUnit test, the following message appears in the 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();
    }
    
          

  • These warnings can be easily taken care of by implementing options glue

    for cucumber.



Let me know if this answers your question.

0


source







All Articles