Search code examples
javawebdrivercucumberbdd

How to resolve runtime.cucumberexception for error parsing feature file


I just created simple java file which is used to execute the feature file through cucumber, but Its failed, and throws following run time exception

Exception in thread "main" cucumber.runtime.CucumberException: Error parsing feature file C:/Users/XXX/XXXX/src/test/java/RunTest.java
    at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:133)
    at cucumber.runtime.model.CucumberFeature.loadFromFeaturePath(CucumberFeature.java:102)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:54)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:34)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:201)
    at cucumber.runtime.Runtime.run(Runtime.java:109)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: gherkin.lexer.LexingError: Lexing error on line 1: 'package test.java;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(features="src/test/resources/")
    public class RunTest extends AbstractTestNGCucumberTests {
    }

Feature file:

Feature: Search India on BBC website and verify search.

@Search
  Scenario Outline: Search India on BBC website and verify it.
    Given I open the firefox browser
    And I navigating to BBc website
    Then I click at search textbox
    And I enter "India" in search textbox
    And I click at Search button
    Then I should be taken to search page
    And I verify India on search page

Can somebody tell me how to resolve this issue?


Solution

  • When using a Scenario Outline, you need to provide an "Examples" section. In this case, it looks like you don't need a scenario outline at all, so:

    Feature: Search India on BBC website and verify search.
    
      @Search
      Scenario: Search India on BBC website and verify it.
        Given I open the firefox browser
        And I navigating to BBc website
        Then I click at search textbox
        And I enter "India" in search textbox
        And I click at Search button
        Then I should be taken to search page
        And I verify India on search page
    

    If you do need a scenario outline, you want something like:

    Feature: Search India on BBC website and verify search.
    
      @Search
      Scenario Outline: Search India on BBC website and verify it.
        Given I open the firefox browser
        And I navigating to BBc website
        Then I click at search textbox
        And I enter "<country>" in search textbox
        And I click at Search button
        Then I should be taken to search page
        And I verify <country> on search page
    
      Examples:
        | country |
        | India   |
        | China   |