2011-07-11 77 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天以來我一直在尋找這個解決方案..你讓我的一天:) –