当我用ruby编写代码进行自动测试时,如何修复小黄瓜中的Parser Error

时间:2019-02-16 07:11:32

标签: ruby cucumber

我创建了search.featuresearch.rb文件来建立自动测试。之后,我在终端上运行命令并得到一个错误。如何解决?

我已经在Windows Ruby 2.6.1Cucumber 3.1.2上的Linux子系统上尝试过

这是 search.feature 文件的代码:

    The google homepage allows user to perform a search.

    Scenario Outline: Users can perform a search on Google
        Given I open the Google search page
        When I search for "<search>"
        Then I should see the results page

    Examples :
        | search    |
        | baju      |
        | bola      |
        | indonesia |

这是 search.rb 文件的代码:

Given /^I open the Google search page$/ do
    visit "/"
end

Given /^I search for "(.*?)"$/ do |search_term|
    @page_search = SearchPage.new
    @page_search.search(search_term)
end

Then /^I should see the results page$/ do
    expect(@page_search).to have_search_field
end

在那之后,当我在终端上运行命令时,出现了这样的错误:

➜  cucumber-native cucumber
features/scenario/search/search.feature: Parser errors:
(9:2): expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ExamplesLine, #ScenarioLine, #ScenarioOutlineLine, #Comment, #Empty, got 'Examples :' (Cucumber::Core::Gherkin::ParseError)
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:34:in `rescue in document'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:28:in `document'/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:30:in `block in parse'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `each'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `parse'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:21:in `compile'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/lib/cucumber/runtime.rb:75:in `run!'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/lib/cucumber/cli/main.rb:34:in `execute!'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/bin/cucumber:9:in `<top (required)>'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/cucumber:23:in `load'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/cucumber:23:in `<main>'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'



1 个答案:

答案 0 :(得分:1)

Examples部分必须嵌套在Scenario

Scenario Outline: Users can perform a search on Google
    Given I open the Google search page
    When I search for "<search>"
    Then I should see the results page

    Examples:
        | search    |
        | baju      |
        | bola      |
        | indonesia |