【发布时间】:2011-07-11 22:53:06
【问题描述】:
我是一个相对新手,正在启动一个新的 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_tags 的表单,但我无法成功获得一个场景通过一个基本的And I press "button" 步骤。
可能相关的宝石:
导轨(3.1.0.rc4) 水豚 (1.0.0) 黄瓜 (1.0.1) 黄瓜导轨 (1.0.2) nokogiri (1.4.7) 小黄瓜 (2.4.5) 机架测试(0.6.0) 硒网络驱动程序(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">
很明显,我计算了value、id、text,以及name 和title。我还看到一个帖子说输入类型必须指定为submit,它似乎是。我用confirm 按钮和cancel 按钮都试过了。
在搜索了我所知道的所有地方,并尝试了每一个看起来甚至无关紧要的建议之后,我陷入了僵局。我错过了什么?
【问题讨论】:
-
在调用该步骤时,您确定 cucumber 实际上在正确的页面上吗? Capybara 有一个非常有用的 'save_and_open_page' 方法。尝试将它放在 web_steps.rb 中的 click_button 调用之上,并检查它是否真的在正确的页面上。
标签: ruby-on-rails cucumber bdd capybara ruby-on-rails-3.1