我正在尝试使用Cocoon和rails 4为具有嵌套属性的表单编写测试。问题是我找不到要设置的表单元素。
我尝试了以下注释掉的变体,但未找到元素:
click_link('Add Owner') # should display the fields
#fill_in 'First Name', with: "sean"
#find("input#horse_owner_attributes_fname").set('sean')
#find(:xpath, '//input[@id="horse_owner_attributes_lname"]').set("sean")
我不确定我的问题是茧'link_to_add_association'的动态性质,还是我不知道如何使用find或其他原因。
我的主要形式是:
#owner
#owner_from_list
= f.collection_select(:owner_id, @owners, :id, :fname, { :prompt => "Existing Owner" }, {:class => 'form-control'} ) # shows drop down of existing records
= link_to_add_association 'Add Owner', f, :owner, :class => "btn btn-default btn-sm", :data => {"association-insertion-method" => "after" } # to add a new record
和我的添加所有者部分:
= f.inputs do
.nested-fields
= f.input :fname, :as => :string, label: "First Name", hint: "Owner's first name REQUIRED", :required => true
= f.input :lname, :as => :string, label: "Last Name", hint: "Last name REQUIRED", :required => true
看来我遇到了问题。
如果您要填写在单击Cocoon链接后动态添加的字段,则应将其js: true
作为选项传递给相关方案。
您可以看到我的问题和克里斯·彼得斯给我的出色回答:rspec看不到茧以嵌套形式动态添加或删除的字段以获取更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句