'I got Initialization error in Cucumber with maven and selenium

Test Runner
import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(features="features",glue={"stepDefinition"})
public class TestRunner {

}

MyApplication.feature

Feature: Test test smoke scenario

  Scenario Outline: Test  login with valid credentials
    Given open fireFox and start application
    When I enter valid "username" and valid "password"
    Then User should be able to login successfully

Examples: 
      | username   | password          |
      | 9739817000 | mnbvcxz  |
      | 9739817001 | mnbvcxz1  |
      | 9739817002 | mnbvcxz2  |

Maven POM

<groupId>demo</groupId>
  <artifactId>prac</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>prac</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency> 
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>
  

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.4</version>
</dependency>
</dependencies>
</project>

Smoke.java

public class Smoke {
    WebDriver driver;
    @Given("^open fireFox and start application$")
    public void open_fireFox_and_start_application() throws Throwable {
        driver=new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://testweb.com");
        
    }

    @When("^I click on Login$")
    public void I_click_on_Login() throws Throwable {
        driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();
        

    }

    @When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
    public void enter_valid_and_valid(String un, String pwd) throws Throwable {
        driver.findElement(By.id("Username")).sendKeys(un);
        driver.findElement(By.id("Password")).sendKeys(pwd);
        
    }

    @Then("^Click on Login$")
    public void Click_on_Login() throws Throwable {
        driver.findElement(By.id("loginUser")).click();
        
    }
    @Then("^User should be able to login successfully$")
    public void User_should_be_able_to_login_successfully() throws Throwable {
        
       
    }

These above are the test runner,feature file,Smoke test class. Its throwing an Initilization error.I am new to Cucumber and recheck all the maven dependency ,its correct only.But even also its giving error

enter image description here



Solution 1:[1]

As, you have not specified any sets of data for your feature file, you do not need to use Scenario Outline. You can use it when you need to execute same scenario with different sets of data. Hence, remove Scenario Outline from your feature file (shown below the updated feature file) and retry:

Feature: Test Milacron smoke scenario

Scenario: Test  login with valid credentials
Given open fireFox and start application
When I enter valid "username" and valid "password"
Then User should be able to login successfully

Please refer to link for more details about writing feature files. Let me know, if you have any further queries.

Solution 2:[2]

Scenario Outline is used to pass different sets of input data to your scenario. For instance 'ABC' and 'PWD' are your username, password respectively then update your feature file as below,

Feature: Test Milacron smoke scenario
Scenario Outline: Test  login with valid credentials
Given open fireFox and start application
When I enter valid "username" and valid "password"
Then User should be able to login successfully

Examples:
 | username      | password |
 | ABC           |  PWD     |

Solution 3:[3]

What worked for me was to remove the empty feature files (those without any scenarios present) from the features directory.

Solution 4:[4]

Your pom file is absolutely fine.

Here you are using Scenario Outline if you are using Scenario outline there should be Examples annotation in the feature file. Anyways your test scenario can be achieved without using scenario outline

Update feature file and java file with below code:

Myapplication.feature: Feature: Test test smoke scenario

  Scenario: Test  login with valid credentials
     Given open fireFox and start application
     When I click on Login
     When I enter valid "username" and valid "password"
     Then I click on Loginbutton
     Then User should be able to login successfully

Smoke.java:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Smoke {
   WebDriver driver;
@Given("^open fireFox and start application$")
public void open_fireFox_and_start_application() throws Throwable {
    driver=new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("https://testweb.com");

}

 @When("^I click on Login$")
    public void I_click_on_Login() throws Throwable {
        driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();
    }

@When("^I enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
public void i_enter_valid_and_valid(String arg1, String arg2) throws   Throwable {
    driver.findElement(By.id("Username")).sendKeys(arg1);
    driver.findElement(By.id("Password")).sendKeys(arg2);
}


@Then("^I click on Loginbutton$")
public void Click_on_Login() throws Throwable {
    driver.findElement(By.id("loginUser")).click();

}
@Then("^User should be able to login successfully$")
public void User_should_be_able_to_login_successfully() throws Throwable {


}
}

Maintain Folder structure as mentioned in the attached image enter image description here

If you want to use scenario outline update feature file like below Same smoke.java file will works in this case.

Feature: Test test smoke scenario

 Scenario Outline: Test  login with valid credentials
  Given open fireFox and start application
  When I click on Login
  When I enter valid "<username>" and valid "<password>"
  Then I click on Loginbutton
  Then User should be able to login successfully

Examples:
  |username|password|
  |test|test|

Let me know if it works for you

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahipal
Solution 2 MamathaMacherla
Solution 3 khriskooper
Solution 4 Rakesh kumar