【问题标题】:Capybara form value set with cocoonCapybara 形式值集与茧
【发布时间】:2014-09-26 14:30:55
【问题描述】:

我正在尝试使用 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  

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 nested-attributes cocoon-gem


    【解决方案1】:

    看来我遇到了问题。

    如果您想填写点击 Cocoon 链接后动态添加的字段,您应该将 js: true 作为选项传递给相关场景。

    您可以看到我的问题以及 Chris Peters 给我的出色回答: rspec doesn't see fields dynamically added or removed by cocoon in nested form了解更多信息。

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      相关资源
      最近更新 更多