Siluni Pathirana
Siluni Pathirana

Reputation: 429

gherkin.lexer.LexingError: Lexing error on line 1

When I run my first test file with Cucumber I got this exception How to solve this?

Exception in thread "main" cucumber.runtime.CucumberException: Error parsing feature file D:/intalled/CucumberConcepts/src/cucumber/features/myfeature.feature
at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:123)
at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:52)
at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:33)
at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:143)
at cucumber.runtime.Runtime.run(Runtime.java:107)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:16)

Caused by: gherkin.lexer.LexingError: Lexing error on line 1: 'Feature : Proof of concept that my framework works

This is my test file

Feature : Proof of concept that my framework works

Scenario Outline : My first Test
  Given this is my first test
  When This is my second step
  Then This is the final step

Upvotes: 1

Views: 14610

Answers (4)

shwetha
shwetha

Reputation: 1

Check with the spaces in the feature file. Ex: for Scenario check with the colon and for Given, When and Then there shouldn't be colon and more spaces.

Ex: Scenario:Check with the spaces here Given this is my given When this is my when Then this is my then

Upvotes: 0

Arpan Saini
Arpan Saini

Reputation: 5201

That's a Gherkin Syntax Error : You can't have space between Keywords and Colon.


Actual = Feature :
Expected = Feature:

Actual = Scenario Outline :
Expected = Scenario Outline:


Scenario Outline: will always be used with Examples,

Now When to Use Scenario Outline: and when to use Scenario: ?

Scenario Outline:

This is used when you have to test the same screen, with multiple sets of data

Scenario:

This is used when you have to test one scenario with one set of data or No data

In your Case:

You are testing feature with no data set. So you Should use Scenario instead of Scenario Outline.

Expected Feature:

Feature: Proof of concept that my framework works

Scenario: My first Test
  Given this is my first test
  When This is my second step
  Then This is the final step

Upvotes: 2

Vaibs
Vaibs

Reputation: 2106

Just to addon as the cause of the error is not only the things mentioned by orde.

Feature: Proof of concept that my framework works

Scenario: My first Test
  Given this is my first test
  When This is my second step
  THEN This is the final step

Check that the "Then" keyword is all caps which is supposed to be in proper Syntactical manner. This damn sure leads to the lexical error.

Upvotes: 0

orde
orde

Reputation: 5283

You need to do a couple of things: A) remove the spaces in Feature : and Scenario Outline : keywords; and B) change the Scenario Outline to Scenario (or add the missing examples for the outline).

If you run this feature:

Feature: Proof of concept that my framework works

Scenario: My first Test
  Given this is my first test
  When This is my second step
  Then This is the final step

Then cucumber will output the to-be-completed step definitions:

You can implement step definitions for undefined steps with these snippets:

Given(/^this is my first test$/) do
  pending # Write code here that turns the phrase above into concrete actions
end

When(/^This is my second step$/) do
  pending # Write code here that turns the phrase above into concrete actions
end

Then(/^This is the final step$/) do
  pending # Write code here that turns the phrase above into concrete actions
end

Upvotes: 8

Related Questions