尝试跟踪表中的链接时无法通过 Cucumber 脚本

发布于 2024-09-18 21:57:06 字数 1544 浏览 7 评论 0原文

我正在将 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"

它通过,没有错误。我查看了水豚附带的 web_steps.rb,我使用的似乎是正确的:

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

I am using Rails 3 with Cucumber, Capybara and Factory_Girl. I am trying to test following the "Show" link for just one of the rows on an HTML table. I am using the syntax:

And I follow "Show" within "Net 30"

I gives me the following error:

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

Here is the full Cucumber script that fails:

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"

If I change that line to just say:

And I follow "Show"

It passes with no errors. I looked in the web_steps.rb that came with Capybara and what I am using appears to be correct:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我入戏太深 2024-09-25 21:57:06

我相信 Cucumber 需要一个有效的 XPath 选择器。尝试编写一个 XPath 查询,该查询将选择包含带有文本“Net 30”的单元格的 TR。此链接可能会有所帮助:xpath 获取表内的行

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

骄兵必败 2024-09-25 21:57:06

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

Nokogiri is throwing an error at the CSS selector Net 30 because, of course, it's not a valid CSS selector. I think you're looking for an element whose text is "Net 30", which is very different.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文