运行最新版本的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)
非常感谢任何帮助或指示。
由于
答案 0 :(得分:0)
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"
答案 1 :(得分:0)
您只需编写一个步骤
即可When(/^Click button with value "([^"]*)"$/) do |value|
#click_link_or_button btn_text
find_button(value).click
end