简体   繁体   English

Cucumber::Core::Gherkin::ParseError:如何解决?

[英]Cucumber::Core::Gherkin::ParseError: how to solve it?

I am a newbie in ruby and want to build an autotesting system for a webapplication.我是 ruby 的新手,想为 web 应用程序构建一个自动测试系统。 I started to study the bunch od capybara + cucumber on ruby.我开始研究 ruby 上的水豚 + cucumber。

I found an example and tried to reproduce it.我找到了一个例子并试图重现它。 There is the project sturcture:有项目结构:

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

Feature file has the text:功能文件有以下文字:

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

and step_definitions和 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  

When I run the test, then I got parser errors当我运行测试时,我得到了解析器错误

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

I've been fighting all day, but I can't understand what the problem is.我整天都在吵架,但我不明白问题出在哪里。 Could you help me?你可以帮帮我吗?

Did you tried to add some tags?您是否尝试添加一些标签?

Feature: Log in to site @Example 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功能:登录站点@示例场景:以英语登录站点给定 Go 到页面“http://localhost:3000/login”和 Select 文本“English”在下拉列表 id “lang”中等待 5 秒

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何学习/教黄瓜黄瓜 - How to learn/teach Gherkin for Cucumber 升级Cucumber 2.4-&gt; 4.0失败:无法加载此类文件-Cucumber / Core / Gerkin / tag_expression(LoadError) - Upgrade Cucumber 2.4 -> 4.0 failed: cannot load such file — cucumber/core/gherkin/tag_expression (LoadError) 如何获得有关Gherkin /黄瓜和Ruby的用户输入? - How do I get user input for Gherkin/Cucumber & Ruby? 黄瓜 - 如何从这个小黄瓜场景中删除数据重复? - Cucumber - How to remove data duplication from this Gherkin scenario? 如何将已解析的小黄瓜保存到功能文件(Ruby) - How to save a parsed Gherkin into a Feature File (Ruby) 在Spacemacs中转到黄瓜步骤定义会引发异常:“无法加载此类文件-小黄瓜” - Go to cucumber step definition in Spacemacs throws an exception: “Can not load such file — gherkin” 如何从Rails 4中的ActionDispatch :: ParamsParser :: ParseError中解救 - How to Rescue from ActionDispatch::ParamsParser::ParseError in Rails 4 LoadError:无法在运行命令rackup,ruby版本2.2.0和黄瓜2.1.0上加载此类文件— gherkin / formatter / json_formatter - LoadError: cannot load such file — gherkin/formatter/json_formatter , on running command rackup ,ruby version 2.2.0 and cucumber 2.1.0 无法加载这样的文件 - 2.2 / gherkin_lexer_en,如何修复? - cannot load such file — 2.2/gherkin_lexer_en, how to fix? 如何使Gherkin检查log.info消息是否已打印? - How to make Gherkin check if the log.info message was printed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM