黄瓜“按下按钮”失败(Capybara::ElementNotFound)
我是一个相对新手,正在启动一个新的 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 。当一切似乎都正常工作时,我开始编写我的第一个 Cucumber 功能和步骤。我能够启动并运行几个步骤,但我一直在一个我认为内置的步骤上陷入困境。我有一个带有两个 submit_tag
的表单,但我不能获得一个成功通过基本并且我按“按钮”
步骤的场景。
可能相关的宝石:
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">
显而易见,我已经考虑了 value
、id
、text
以及 name
和 title< /代码>。我还看到一篇文章说输入类型必须指定为
submit
,看起来确实如此。我已经尝试过使用确认
按钮和取消
按钮。
在搜索了我所知道的所有地方,并尝试了每一个看似相关的建议后,我陷入了僵局。我缺少什么?
I'm a relative newbie starting up a new Ruby on Rails app. I started by following a combination of instructions at 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 . At the point everything appeared to work correctly, I started to write my very first cucumber features and steps. I was able to get a couple of steps up and running, but I've been bogged down on a step that I thought was built in. I have a form with two submit_tag
s but I can't get a scenario to successfully pass a basic And I press "button"
step.
possibly relevant gems:
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)
section of the form in question:
<%= 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 in question:
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!"
I think this is the relevant web_step (straight from the default web_steps.rb which I have not edited at all):
When /^(?:|I )press "([^"]*)"$/ do |button|
click_button(button)
end
relevant cucumber output:
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
relevant html output:
<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">
As is obvious, I've accounted for value
, id
, text
, as well as name
and title
. I also saw a post that said the input type had to be specified as submit
which it appears to have been. And I've tried it with both the confirm
button and the cancel
button.
After searching everywhere that I know about, and trying every suggestion that looked even remotely relevant, I'm at an impasse. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定下面的代码是否是处理我遇到的问题的最佳方法,但它正在通过相关步骤。
我仍然感谢任何反馈:
I'm not sure if the code below is the best way to deal with the problem I encountered, but it is getting the relevant step to pass.
I'd still appreciate any feedback on: