尝试跟踪表中的链接时无法获取Cucumber脚本

时间:2010-09-10 01:52:23

标签: ruby-on-rails testing cucumber capybara

我正在使用Rails 3与Cucumber,Capybara和Factory_Girl。我试图测试HTML表上的其中一行的“显示”链接。我正在使用语法:

And I follow "Show" within "Net 30"

我给了我以下错误:

unexpected '30' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `_racc_do_parse_c'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `__send__'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `do_parse'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
features/view_payment_terms.feature:10:in `And I follow "Show" within "Net 30"'

以下是完整的Cucumber脚本失败:

Feature: View Payment Terms
  In order to view payment terms
  As a user
  I want to view payment terms

    Scenario: View Payment Terms
      Given there is a payment term named "Net 30"
      And there is a payment term named "Net 60"
      When I go to the "payment terms screen"
      And I follow "Show" within "Net 30"
      Then I should see "Terms description: Net 30"

如果我改变该行只是说:

And I follow "Show"

它通过没有错误。我查看了Capybara附带的web_steps.rb以及我使用的内容似乎是正确的:

When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
  with_scope(selector) do
    click_link(link)
  end
end

2 个答案:

答案 0 :(得分:1)

我相信Cucumber想要一个有效的XPath选择器。尝试编写一个XPath查询,该查询将选择包含文本“Net 30”的单元格的TR。此链接可能有所帮助:xpath to get rows inside a table

答案 1 :(得分:0)

Nokogiri在CSS选择器Net 30上抛出一个错误,因为它当然不是一个有效的CSS选择器。我想你正在寻找一个 text 是“Net 30”的元素,这是非常不同的。