0

谷歌搜索并没有找到有效的解决方案...使用 Rails 3.2.11,RSpec 2.12.2 Capybara 2.0.2 我正在尝试测试表单上的“重置按钮”(使用浏览器测试时效果很好)

我试过这段代码

scenario "Fill form then reset it" do
  visit contact_path
  fill_in 'message_name', :with => 'abc'
  fill_in 'message_email', :with => 'abc'
  fill_in 'message_subject', :with => 'abc'

  click_on 'Reset form'

  expect(page).to find_field('message_name').value.should == ''
end

测试失败并出现此错误

 expected: ""
 got: "abc"
(compared using ==)

似乎这些字段根本没有重置..(但在浏览器中它们是)

我错过了什么?这个版本的 Capybara 或 Rspec 有什么新东西吗?

谢谢你的帮助

4

1 回答 1

1

我的错,

这种类型的功能/场景需要js驱动。

硒包含在水豚宝石中,但我忘记在我的功能中激活它。为了让它工作,我只需要换线

scenario "Fill form then reset it" do

对这个

scenario "Fill form then reset it", :js => true do

根据文档https://github.com/jnicklas/capybara#using-capybara-with-rspec。现在一切正常...

希望它可以帮助别人......干杯

于 2013-01-30T17:36:48.687 回答