黄瓜::核心::小黄瓜:: ParseError:如何解决?

时间:2019-10-27 16:55:04

标签: ruby parsing cucumber capybara

我是ruby的新手,想为Web应用程序构建一个自动测试系统。我开始研究红宝石上的一堆水豚+黄瓜。

我找到了一个例子,并试图复制它。有项目结构:

devTests
     features
      step_definitions
        test_steps.rb
      support
        env.rb
      tests
        test_send_mail.feature
     Gemfile
     Gemfile.lock

功能文件包含以下文本:

Feature: Log in to site
  Scenario: Log in to site on English
    Given Go to page "http://localhost:3000/login"
    And Select text "English" in dropdownlist id "lang"
    And Wait 5 second
    And Input text "admin" in field with id "session_email"
    And Input text "123" in field with id "session_password"
    And Press button with text "Log in"
    And Wait 5 second

和step_definitions

Given(/^Go to page "(.*?)"$/) do |page|
  visit page
end

Given(/^Select text "(.*?)" in dropdownlist id "(.*?)"$/) do |text, select_id|
  find("//select[@id='#{select_id}']/option[text()='#{text}']").click
end

Given(/^Wait (\d+) second(?:|s)$/) do |sec|
  sleep sec.to_i
end 

Given(/^Input text "(.*?)" in field with id "(.*?)"$/) do |text, field_id|
  find("//input[@id='#{field_id}']").set(text)
end

Given(/^Input text "(.*?)" in field with id "(.*?)"$/) do |text, field_id|
  find("//input[@id='#{field_id}']").set(text)
end

Given(/^Press button with text "(.*?)"$/) do |text|
  find("//input[@value='#{text}']").click
end

Given(/^Wait (\d+) second(?:|s)$/) do |sec|
  sleep sec.to_i
end  

运行测试时,出现解析器错误

PS D:\07 TestConwize\devTests> cucumber
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
features/tests/test_send_mail.feature: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Feature: Log in to site'
(2:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Scenario: Log in to site on English'    
(3:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Given Go to page "http://localhost:3000/login"'
(4:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Select text "English" in dropdownlist id "lang"'
(5:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Wait 5 second'
(6:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Input text "admin" in field with id 
"session_email"'
(7:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Input text "123" in field with id "session_password"'
(8:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Press button with text "Log in"'    
(9:5): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'And Wait 5 second' (Cucumber::Core::Gherkin::ParseError)
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:34:in `rescue in document'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:28:in `document'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:30:in `block in parse'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `each'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `parse'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:21:in `compile'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/lib/cucumber/runtime.rb:75:in `run!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/lib/cucumber/cli/main.rb:34:in `execute!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/bin/cucumber:9:in `<top (required)>'
C:/Ruby25-x64/bin/cucumber:23:in `load'
C:/Ruby25-x64/bin/cucumber:23:in `<main>'

我整天都在战斗,但是我不明白问题是什么。 你能帮我吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试添加一些标签?

功能:登录网站 @例 场景:以英语登录站点 转到页面“ http:// localhost:3000 / login” 并在下拉列表ID“ lang”中选择文本“ English” 然后等待5秒钟