2011-07-11 58 views
2

我是一个相对的新手启动一个新的Ruby on Rails应用程序。我从https://github.com/intridea/omniauth,http://www.communityguides.eu/articles/16,http://intridea.com/2011/1/31/easy-rails-admin-login-with-google-apps-and-omniauth?blog=company的指令组合开始。在一切似乎正常工作,我开始写我的第一个黄瓜的功能和步骤。我能够启动和运行几个步骤,但是我陷入了一个我认为是内置的步骤。我的表格有两个submit_tag s,但是我无法成功通过一个场景基本And I press "button"一步。黄瓜`按钮按钮失败(水豚:: ElementNotFound)

可能相关的宝石:形式的问题

 
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) 

部分:

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(直线距离:

<%= 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 %> 

问题方案我没有编辑过的默认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按钮试过了。

在到处搜索了解我所知道的各种建议之后,尝试了一些看起来甚至是远程相关的建议,但我陷入了僵局。我错过了什么?

+3

你确定黄瓜实际上是在正确的页面上的步骤被称为?水豚有一个非常有用的'save_and_open_page'方法..尝试把它放在web_steps.rb中的click_button调用之上,并检查它是否在正确的页面上。 – idlefingers

回答

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版本失败,
  • 这是否是一个合适的方法或没有,
  • 如果有一个更“轨道”的方式来处理这个问题。
+0

感谢@MacSean它也适用于我。自从最近3天以来我一直在寻找这个解决方案..你让我的一天:) –