2

我正在使用带有 Cucumber、Capybara 和 Factory_Girl 的 Rails 3。我正在尝试按照 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
4

2 回答 2

1

I believe Cucumber wants a valid XPath selector there. Try writing an XPath query that will select the TR containing a cell with the text "Net 30" in it. This link may help: xpath to get rows inside a table

于 2010-10-24T20:52:36.710 回答
0

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

于 2013-03-16T11:02:17.560 回答