黄瓜`按钮`失败(Capybara :: ElementNotFound) [英] Cucumber `press button` failure (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 。在一切似乎工作正常,我开始写我的第一个黄瓜的特点和步骤。我可以得到几个步骤和运行,但我已经陷入了一个步骤,我认为是内置的。我有一个窗体与两个 submit_tag
但我不能得到一个成功通过一个基本的的场景,我按按钮
步骤。
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.
可能相关的宝石:
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,我没有编辑所有):
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
相关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
。我也看到一个帖子,说输入类型必须指定为提交
它看起来是。我已经尝试过 confirm
按钮和 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?
推荐答案
我不知道下面的代码是否是处理我遇到的问题的最好方法,相关步骤通过。
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.
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版本失败,
- 是否是合适的方法,
- 如果有更多的'rails'
- why the original web_steps.rb version fails,
- whether this is an appropriate approach or not, and
- if there is a more 'rails' way to deal with this.
这篇关于黄瓜`按钮`失败(Capybara :: ElementNotFound)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!