我怎样才能检查一个表单域使用水豚正确预填?
我有一个适当的标签,我可以用水豚填写没有问题的领域:
fill_in 'Your name', with: 'John' 我想在填写之前检查它的价值,并不能弄清楚。
 如果我在fill_in之后添加以下行: 
 find_field('Your name').should have_content('John') 
该testing失败,虽然之前填写工作,因为我通过保存页面validation。
我错过了什么?
 你可以使用xpath查询来检查是否有一个特定值的input元素(例如'John'): 
 expect(page).to have_xpath("//input[@value='John']") 
有关更多信息,请参阅http://www.w3schools.com/xpath/xpath_syntax.asp 。
或许更漂亮的方式:
 expect(find_field('Your name').value).to eq 'John' 
编辑:现在我可能会使用have_selector
 expect(page).to have_selector("input[value='John']") 
如果你正在使用页面对象模式(你应该!)
 class MyPage < SitePrism::Page element :my_field, "input#my_id" def has_secret_value?(value) my_field.value == value end end my_page = MyPage.new expect(my_page).to have_secret_value "foo" 
另一个漂亮的解决scheme是:
 page.should have_field('Your name', with: 'John') 
要么
 expect(page).to have_field('Your name', with: 'John') 
分别。
另请参阅参考 。
  注意 :对于禁用的input,您需要添加disabled: true选项disabled: true 。 
如果您特别想testing占位符,请使用:
 page.should have_field("some_field_name", placeholder: "Some Placeholder") 
要么:
 expect(page).to have_field("some_field_name", placeholder: "Some Placeholder") 
如果你想testing用户input的值:
 page.should have_field("some_field_name", with: "Some Entered Value") 
我想知道如何做一些稍微不同的事情:我想测试这个领域是否有一定的价值(同时利用水豚的能力重新testing匹配器,直到匹配 )。 事实certificate,可以使用“过滤块”来做到这一点:
 expect(page).to have_field("field_name") { |field| field.value.present? }