黄瓜`按钮'失败(Capybara :: ElementNotFound)

时间:2011-07-11 22:53:06

标签: ruby-on-rails cucumber bdd capybara ruby-on-rails-3.1

我是一个相对新手,启动了一个新的Ruby on Rails应用程序。我首先遵循https://github.com/intridea/omniauthhttp://www.communityguides.eu/articles/16http://intridea.com/2011/1/31/easy-rails-admin-login-with-google-apps-and-omniauth?blog=company的一系列说明。在这一切似乎一切正常,我开始写我的第一个黄瓜功能和步骤。我能够启动并运行几个步骤,但是我已经陷入了我认为内置的一个步骤。我有一个有两个submit_tag的表单,但我无法得到一个场景成功通过基本And I press "button"步骤。

可能相关的宝石:

rails (3.1.0.rc4)
capybara (1.0.0)
cucumber (1.0.1)
cucumber-rails (1.0.2)
nokogiri (1.4.7)
gherkin (2.4.5)
rack-test (0.6.0)
selenium-webdriver (0.2.2)

相关表单的部分:

<%= form_tag :controller => "services", :action => "newaccount" do %>
  <%= submit_tag "confirm", :id => "confirm", :title => "confirm", :value => "confirm", :text => "confirm", :name => "confirm" %> 
  <%= submit_tag "cancel", :id => "cancel", :title => "cancel", :value => "cancel", :text => "cancel", :name => "cancel"  %>
<% end %>

有问题的情景:

Scenario: I register with a valid and currently active google account
    Given I am not registered
     When I sign in with a valid and currently active google account
      And I press "confirm"  # <-- THE PROBLEMATIC STEP
     Then I should see "Your account has been created and you have been signed in!"

我认为这是相关的web_step(直接来自默认的web_steps.rb,我根本没有编辑过):

When /^(?:|I )press "([^"]*)"$/ do |button|
  click_button(button)
end

相关黄瓜产量:

Scenario: I register with a valid and currently active google account            # features/auth_and_auth/initial_tests.feature:6
  Given I am not registered                                                      # features/step_definitions/authentication_steps.rb:1
  When I sign in with a valid and currently active google account                # features/step_definitions/authentication_steps.rb:5
  And I press "confirm"                                                          # features/step_definitions/web_steps.rb:52
    no button with value or id or text 'confirm' found (Capybara::ElementNotFound)
    (eval):2:in `click_button'
    ./features/step_definitions/web_steps.rb:53:in `/^(?:|I )press "([^"]*)"$/'
    features/auth_and_auth/initial_tests.feature:9:in `And I press "confirm"'
  Then I should see "Your account has been created and you have been signed in!" # features/step_definitions/web_steps.rb:105

相关的html输出:

<input id="confirm" name="confirm" text="confirm" title="confirm" type="submit" value="confirm">
<input id="cancel" name="cancel" text="cancel" title="cancel" type="submit" value="cancel">

很明显,我已经考虑了valueidtext以及nametitle。我还看到一篇帖子说输入类型必须指定为submit,它似乎已经存在。我已经使用confirm按钮和cancel按钮尝试了它。

在搜索了我所知道的所有地方,并尝试了一些看起来甚至相关的建议之后,我陷入了僵局。我错过了什么?

1 个答案:

答案 0 :(得分:3)

我不确定下面的代码是否是处理我遇到的问题的最佳方法,但它正在通过相关步骤。

When /^(?:|I )press "([^"]*)"$/ do |button|
# click_button(button)  # the original web_steps.rb version that fails
  %{I press (button)}   # my revised version that passes
end

我仍然感谢任何反馈:

  • 原始web_steps.rb版本失败的原因,
  • 这是否合适,
  • 如果有更多“轨道”方式来解决这个问题。