Ruby on rails 水豚找不到表单字段
我第一次尝试水豚,但在找到我的身体时遇到了麻烦。我正在使用Rspec、Capybara、rails3.2.8和Twitter引导 在我的测试中,我有:Ruby on rails 水豚找不到表单字段,ruby-on-rails,ruby-on-rails-3,rspec,integration-testing,capybara,Ruby On Rails,Ruby On Rails 3,Rspec,Integration Testing,Capybara,我第一次尝试水豚,但在找到我的身体时遇到了麻烦。我正在使用Rspec、Capybara、rails3.2.8和Twitter引导 在我的测试中,我有: before do choose "Residential" choose "Storage" fill_in "Customer Location", with: 30082 fill_in "datepicker", with: 2012-12-02 fill_in "Email",
before do
choose "Residential"
choose "Storage"
fill_in "Customer Location", with: 30082
fill_in "datepicker", with: 2012-12-02
fill_in "Email", with: "jesse@test.com"
fill_in "Phone", with: "555-555-5555"
end
并且得到了错误信息:
Failure/Error: choose "Residential"
Capybara::ElementNotFound:
cannot choose field, no radio button with id, name, or label 'Residential' found
在我的表格中,我有(摘录):
当我启动服务器时,我可以看到表单,Firebug显示我有一个名为“住宅”的标签与表单元素关联
在寻找问题并找到这篇文章后:(除其他外),我无法理解为什么它不起作用。我最终回到了Capybara的Rubydocs()并找到了关于“选择”方法的部分 我没有深入阅读文档,但我看到它在:单选按钮中寻找“定位器”,因此尝试直接将其关联起来 因此,我将表单更改为(注意,我在表单元素中添加了“id”):
那部分测试通过了!我重复了我的每一个表单元素,并按照预期执行了所有操作
希望这对其他人有用。我最终回到了Capybara的Rubydocs()中,找到了关于“Choose”方法的部分 我没有深入阅读文档,但我看到它在:单选按钮中寻找“定位器”,因此尝试直接将其关联起来 因此,我将表单更改为(注意,我在表单元素中添加了“id”):
那部分测试通过了!我重复了我的每一个表单元素,并按照预期执行了所有操作
希望这对其他人有用
<%= quote.radio_button :customer_type, "Residential"%>
<%= quote.label "Residential", class:"radio inline" %>
<%= quote.radio_button :customer_type, "Residential", id:"Residential"%>
<%= quote.label "Residential", class:"radio inline" %>