0
votes

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>'
3

3 Answers

2
votes

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
0
votes

Parser Error has occurred with Given (/^ I am on some career site demo Page$/) do because there is no corresponding Given in the feature file. Instead, the feature file's Given in the question reads Given I am on http://some career site dot com/ which is not the same as what is mentioned in step definition. I suggest following:

  1. Give a User Story tag to your feature file. e.g. Write @US_Something at the start of the feature file as the first line.
  2. From Terminal at parent directory of features, run cucumber -t @US_Something. If there are no issues with feature file, Cucumber will suggest methods to be implemented in your step definition .rb file. Use these method for your onward implementation.
0
votes

i have faced the same issue. i just did "remove BOM" from my intellij editor's File-> File Properties ->Remove BOM.

the file started to get parsed.