2

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?

Helping Hands
  • 5,292
  • 9
  • 60
  • 127

4 Answers4

1

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

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)

Dude
  • 692
  • 1
  • 4
  • 25
1

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 {

   }
N..
  • 906
  • 7
  • 23
  • Thanks , I am getting result better than before but still there is some issue , please check my updated question. – Helping Hands Dec 24 '15 at 04:11
  • 1
    Oh You didn't created step definition that's the problem. When you run runner file, It will create step definition, You copy all that step definition and put in cucumber_test and write code in each step. Run your runner file and You should able to see step definition function console out put and copy that put in cucumber_test. It will have pending exception. Remove that pending exception and put your code according to each step. – N.. Dec 24 '15 at 14:16
  • Sure I will try. Thanks. – Helping Hands Dec 26 '15 at 14:31
  • Where it generate step definition file? can you please help me to find that? – Helping Hands Dec 28 '15 at 09:33
  • When you run runner file, It will generate in console output. If you have right configuration, It should generate step definition. – N.. Dec 28 '15 at 15:28
0

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"

raman rayat
  • 404
  • 5
  • 15