2
votes

Already tried almost all solutions which are on SO but still missing something here.

I have created simple JAVA program, Added Feature file and Class for cucumber. When I run I am getting output :

@Search Scenario Outline: Successful Open Google.com [90m# Open_Google.feature:4[0m [36mGiven [0m[36mUser is with blank page[0m [36mWhen [0m[36mUser enter URL[0m [36mThen [0m[36mGoogle WebSite should open[0m

0 Scenarios

0 Steps

0m0.000s

Feature File :

Feature: Open Google WebSite

@Search
Scenario Outline: Successful Open Google.com
Given User is with blank page
When User enter URL
Then Google WebSite should open 

Test Runner Class :

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(

        features = "Feature"

        )

public class TestRunner {

}

Test Case Class :

public class cucumber_test {

    public static WebDriver driver;

    public static void main(String[] args) {
        // TODO Auto-generated method stub



        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        driver = new ChromeDriver();

        driver.get("http://www.google.com");
        driver.manage().window().maximize();

        System.out.println("Google open successfully");
    }

}

Using Selenium Webdriver, JAVA, Junit and cucumber.

Also Am I doing right? Is it correct method to use cucumber?

4

4 Answers

1
votes

It seems like the runner is unable to find your feature file. Is it located in the resources? If it is, try referencing the whole classpath like

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(

    features = "classpath:com/yourgroup/yourartifact/cucumber/features"

    )

public class TestRunner {

}

Above is just an example, of course you have to alter that classpath depending on where your features are located.

1
votes

You need to reference the location of your features and your step definitions. the runner should look something like this:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(
    features = {"path/to/features/"},
    glue = {"classpath:package.name.of.stepsDefinitions"},
)

public class TestRunner {

}

Note the path notation for the feature files and the package notation for the glue code (step definitions)

1
votes

I believe you still facing same problem. You could try this.

 import org.junit.runner.RunWith;

   import cucumber.api.CucumberOptions;
   import cucumber.api.junit.Cucumber;


   @RunWith(Cucumber.class)@CucumberOptions(plugin = {
    "pretty", "json:target/Open-Google-WebSite.json"},
   features = {"src/test/FeatureFilePackage"},
   glue = {"com.java.cucumber_test"})

    public class TestRunner {

   }
0
votes

it seems your test is running through testng which is not showing any specific error i would recommend you remove testNg dependency from your pom file run your test (through Junit) and you will be able to see specific error and after resolving it you will able to run your class easily

expected error might be "duplicate step defination"