黄瓜“按下按钮”失败(Capybara::ElementNotFound)

发布于 2024-11-23 15:48:20 字数 3252 浏览 0 评论 0原文

我是一个相对新手,正在启动一个新的 Ruby on Rails 应用程序。我首先按照 https://github.com/intridea/omniauthhttp://www.communityguides.eu/articles/16http://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">

显而易见,我已经考虑了 valueidtext 以及 nametitle< /代码>。我还看到一篇文章说输入类型必须指定为 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_tags 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不咬妳我踢妳 2024-11-30 15:48:21

我不确定下面的代码是否是处理我遇到的问题的最佳方法,但它正在通过相关步骤。

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”的方法来处理这个问题。

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

I'd still appreciate any feedback on:

  • 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文