Search code examples
rubycucumberbdd

Cucumber parser error


Here is my directory structure:

C:\Work\Test Scripts\Cucumber\features features\guru.feature features\step_definitions

  • \step_definitions\step-guru.rb

So running the command Cucumber from step_definitions still I see error as below:

c:\Work\Test Scripts\Cucumber\features\step_definitions>cucumber *** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic on/) to get coloured output on Windows No such file or directory - features. You can use cucumber --init to get start ed.

c:\Work\Test Scripts\Cucumber\features\step_definitions>cucumber step-guru.rb *** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic on/) to get coloured output on Windows step-guru.rb: Parser errors: (3:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Given (/^ I am on some career site dot com Page$/) do'

Here is my Feature file:

Feature: Visit Career guide page in some career site
Scenario: Visit some career site dot com
    Given  I am on http://some career site dot com/
    When I click on jobs tab
    Then  I should see Jobs page

And here is my .rb file to run the code:

Given (/^ I am on some career site demo Page$/) do
  Browser.goto "career site" 
end

When (/^ click on Jobs tab$/) do
  Browser.text (:name, "Jobs" ).click 
end

Then (/^ I should see Jobs page$/) do
  Browser.goto "jobs site/"
  puts "Successful Page load"
  browser.close
end

I am getting below Cucumber Parser error. Can you please see it and help me solve this?

c:\Work\Test Scripts\Cucumber\features\step_definitions>cucumber step-guru.rb
*** WARNING: You must use ANSICON 1.31 or higher (githubsite of ansicon) to get coloured output on Windows
step-guru.rb: Parser errors:
(3:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Given (/^ I am on some career site demo Page$/) do'
(5:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Browser.goto "http://some career site dot com"'
(7:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'end'
(11:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'When (/^ click on Jobs tab$/) do'
(13:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Browser.text (:name, "Jobs" ).click'
(15:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'end'
(19:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Then (/^ I should see Jobs page$/) do'
(21:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Browser.goto "http://some career site dot com/jobs/"'
(23:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'puts "Successful Page load"'
(25:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'browser.close'
(27:1): expected: #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'end' (Cucumber::Core::Gherkin::ParseError)
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core/gherkin/parser.rb:34:in `rescue in document'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core/gherkin/parser.rb:29:in `document'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:27:in `block in parse'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:26:in `each'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:26:in `parse'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:18:in `compile'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-2.1.0/lib/cucumber/runtime.rb:70:in `run!'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-2.1.0/lib/cucumber/cli/main.rb:32:in `execute!'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cucumber-2.1.0/bin/cucumber:8:in `<top (required)>'
C:/Ruby200-x64/bin/cucumber:23:in `load'
C:/Ruby200-x64/bin/cucumber:23:in `<main>'

Solution

  • You're calling cucumber the wrong way:

    cucumber step-guru.rb
    

    Cucumber tries to interpret your steps definition file as a features file - instead, you should simply run cucumber from your top-level directory as

    cucumber
    

    provided your project layout is like this:

    TOP/     
       features/  
         first.feature
         steps/
           first_step.rb