【问题标题】:Rails, Cucumber, Capybara - Cucumber step cannot press a buttonRails, Cucumber, Capybara - Cucumber step 无法按下按钮
【发布时间】:2012-02-05 18:25:42
【问题描述】:

运行最新版本的 Rails、Cucumber 和 Capybara 当 Capybara 需要按下按钮时,我遇到了困难。我已尝试消除所有问题,并确保表单已正确生成和显示。

我收到 2 个错误: A)如果我尝试按下具有正确 id 或文本值的按钮('commit') B) 如果我尝试按下带有完全不正确的 id 或文本值的按钮 ('cxxxommit')

我可以在 Ubuntu 和 Windows 7 上重现这些错误。

错误:

选项 A

And I save the Quote
    undefined method `name' for nil:NilClass (ActionView::Template::Error)
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'

选项 B

 And I save the Quote
        no button with value or id or text 'cxxxommit' found (Capybara::ElementNotFound)
        (eval):2:in `click_button'
        ./features/step_definitions/quote_steps.rb:63:in `/^I save the Quote$/'
        features\interactions\policies\quotes.feature:22:in `And I save the Quote'

版本:

ruby 1.9.2p290 (2011-07-09) [i386-mingw32]

Rails 3.1.3

场景

Scenario: Create a complete manual entered quote for a client
    When I select the XXX as YYY          
     And I save the Quote
    Then I should see "Policy was successfully created"

步骤

When /^I select the (.*) as (.*)$/ do |field, value|
    select(value, :from => field)  
end
    
When /^I save the Quote$/ do 
    # debugger  
    click_button('commit')
    # ================================================
    # The next line causes the second error
    # click_button('cxxxommit')
    # ================================================
    # find_button('commit').click
end

请注意,我已阅读并尝试了以下 SO 帖子 Cucumber press button failure (Capybara::ElementNotFound)

List of gems in use

任何帮助或指导将不胜感激。

谢谢

【问题讨论】:

  • 这里有几个不一致的地方。您的方案适用于项目,而不是报价。此外,当您给我们的步骤代码显示“提交”时,您的错误消息显示找不到“cxxxommit”。此外,您有两个错误消息的“选项”吗?您还没有向我们展示哪些代码会导致哪些错误消息。请编辑问题并解决这些问题,最好向我们展示一个最小的失败场景。
  • @MarkThomas:感谢您的快速反馈。我已经更新了问题以反映原始问题,在不同的项目中工作让我很头疼。
  • HTML 是什么样的?它是输入元素还是 javascript 动作?
  • 普通提交按钮。 <input class="create" id="commit" name="Save Quote" type="submit" value="Save Quote" />
  • 这不是一个按钮——它要么是一个复选框,要么是一个收音机。分别尝试检查或选择。

标签: ruby-on-rails ruby-on-rails-3.1 cucumber bdd capybara


【解决方案1】:

你能告诉我以下代码中的项目是什么吗?我想应该是引用

Scenario: Create a complete manual entered quote for a client
    When I select the XXX as YYY          
     And I save the Item
    Then I should see "Item was successfully created"

【讨论】:

  • 100% 正确。感谢您的反馈,请查看更新后的帖子。
【解决方案2】:

你可以简单地写一个步骤为

When(/^Click button with value "([^"]*)"$/) do |value|
   #click_link_or_button btn_text
   find_button(value).click
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-17
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2018-06-06
    • 2012-04-30
    • 2017-06-29
    相关资源
    最近更新 更多