开发者

Can't get Cucumber script to pass when trying to follow a link in a table

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
    开发者_如何学JAVAclick_link(link)
  end
end


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜