黄瓜解析器错误

时间:2015-09-26 09:17:35

标签: ruby cucumber bdd

这是我的目录结构:

C:\ Work \ Test Scripts \ Cucumber \ features 功能\ guru.feature 特征\ step_definitions

  • \ step_definitions \步骤-guru.rb

所以从step_definitions运行命令Cucumber仍然会看到如下错误:

c:\ Work \ Test Scripts \ Cucumber \ features \ step_definitions> cucumber ***警告:您必须使用ANSICON 1.31或更高版本(https://github.com/adoxa/ansic 在/)在Windows上获得彩色输出 没有这样的文件或目录 - 功能。您可以使用cucumber --init开始 编

c:\ Work \ Test Scripts \ Cucumber \ features \ step_definitions> cucumber step-guru.rb ***警告:您必须使用ANSICON 1.31或更高版本(https://github.com/adoxa/ansic 在/)在Windows上获得彩色输出 step-guru.rb:解析器错误: (3:1):预期:#Language,#TagLine,#FeatureLine,#Comment,#Empty,got'Given'  (/ ^我在某个职业网站上的网页$ /)do'

这是我的功能文件:

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

这是运行代码的.rb文件:

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

我正在低于Cucumber Parser错误。你能看到它并帮我解决这个问题吗?

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 个答案:

答案 0 :(得分:0)

你以错误的方式打电话给黄瓜:

cucumber step-guru.rb

Cucumber尝试将您的步骤定义文件解释为功能文件 - 相反,您应该只是从顶级目录运行黄瓜

cucumber

如果您的项目布局如下:

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

答案 1 :(得分:0)

Given (/^ I am on some career site demo Page$/) do发生解析器错误,因为特征文件中没有相应的Given。取而代之的是,问题中的功能文件的Given读取为Given I am on http://some career site dot com/,这与步骤定义中提到的内容不同。我建议:

  1. 将“用户故事”标签赋予功能文件。例如在功能文件的开头将@US_Something写为第一行。
  2. 从功能父目录中的终端,运行cucumber -t @US_Something。如果功能文件没有问题,则Cucumber将建议在步骤定义.rb文件中实施的方法。将这些方法用于以后的实现。

答案 2 :(得分:0)

我也面临同样的问题。我只是从intellij编辑器的“文件”->“文件属性”->“删除BOM”中“删除了BOM”。

文件开始解析。