Capybara form value set with cocoon

Sean Kelley

I am trying to write a test for a form with nested attributes using Cocoon and rails 4. The problem is that I cannot find the form element to set.

I have tried the following commented out variations but get element not found:

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")

I am not sure if my problem is the dynamic nature of the cocoon 'link_to_add_association' or just that I do not know how to use find, or some other reason.

My main form is:

#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

and my add owner partial:

= 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  
Fred Perrin

It looks like a problem I had.

If you want to fill in fields dynamically added after you click on the Cocoon link, you should pass js: true as an option to the related scenario.

You can see my question and the excellent answer Chris Peters give to me : rspec doesn't see fields dynamically added or removed by cocoon in nested form to have more informations.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Use jQuery to set value of hidden field in a form and submit the value

来自分类Dev

nested_form / cocoon:可以将表格行用于嵌套字段吗?

来自分类Dev

使用simple_form和cocoon时无法使select2正常工作

来自分类Dev

缺少部分错误vs按钮在使用simple_form和cocoon时未显示

来自分类Dev

如何编写简洁的 JS if else 语句以通过 Cocoon 动态添加嵌套的 Rails simple_form?

来自分类Dev

MS-Access VBA: How to set field value back to old value if Form_Error event is triggered

来自分类Dev

Capybara won't fill in form fields (although it finds them)

来自分类Dev

Capybara::ElementNotFound:无法找到 css“#transaction_form”

来自分类Dev

使用 `form_validation.php` 时如何使用 CodeIgniter 的 `set_value()` 函数?

来自分类Dev

Rails Cocoon 只读字段

来自分类Dev

Rails Cocoon CoffeeScript 插入前

来自分类Dev

使用simple_form时如何在Capybara测试中选中一个复选框

来自分类Dev

如何在从“execute_script”返回的“Selenium::WebDriver::Element”实例上调用 Capybara 输入 `.set` 方法?

来自分类Dev

Rails-Cocoon-简单表单-无法呈现

来自分类Dev

使用Cocoon进行多态关联的验证失败

来自分类Dev

Rails:Cocoon gem添加和删除字段

来自分类Dev

Rails cocoon gem 产生重复项

来自分类Dev

Rails Cocoon gem 不起作用

来自分类Dev

无法获取form_validation-> set_rules和form_validation-> set_message错误

来自分类Dev

The value of 'form' must inherit from 'BaseModelForm'

来自分类Dev

Change/clear form value on validation error

来自分类Dev

Ruby on Rails 4和cocoon gem:如何中断对cocoon的删除:删除前

来自分类Dev

Ruby on Rails 4和cocoon gem:如何中断对cocoon的删除:删除前

来自分类Dev

RSpec / Capybara调试

来自分类Dev

Deprecation warning from Capybara

来自分类Dev

Capybara Poltergeist ActionCable测试

来自分类Dev

RSpec / Capybara调试

来自分类Dev

Rails Capybara 无法登录

来自分类Dev

CodeIgniter $ this-> form_validation-> set_message

Related 相关文章

  1. 1

    Use jQuery to set value of hidden field in a form and submit the value

  2. 2

    nested_form / cocoon:可以将表格行用于嵌套字段吗?

  3. 3

    使用simple_form和cocoon时无法使select2正常工作

  4. 4

    缺少部分错误vs按钮在使用simple_form和cocoon时未显示

  5. 5

    如何编写简洁的 JS if else 语句以通过 Cocoon 动态添加嵌套的 Rails simple_form?

  6. 6

    MS-Access VBA: How to set field value back to old value if Form_Error event is triggered

  7. 7

    Capybara won't fill in form fields (although it finds them)

  8. 8

    Capybara::ElementNotFound:无法找到 css“#transaction_form”

  9. 9

    使用 `form_validation.php` 时如何使用 CodeIgniter 的 `set_value()` 函数?

  10. 10

    Rails Cocoon 只读字段

  11. 11

    Rails Cocoon CoffeeScript 插入前

  12. 12

    使用simple_form时如何在Capybara测试中选中一个复选框

  13. 13

    如何在从“execute_script”返回的“Selenium::WebDriver::Element”实例上调用 Capybara 输入 `.set` 方法?

  14. 14

    Rails-Cocoon-简单表单-无法呈现

  15. 15

    使用Cocoon进行多态关联的验证失败

  16. 16

    Rails:Cocoon gem添加和删除字段

  17. 17

    Rails cocoon gem 产生重复项

  18. 18

    Rails Cocoon gem 不起作用

  19. 19

    无法获取form_validation-> set_rules和form_validation-> set_message错误

  20. 20

    The value of 'form' must inherit from 'BaseModelForm'

  21. 21

    Change/clear form value on validation error

  22. 22

    Ruby on Rails 4和cocoon gem:如何中断对cocoon的删除:删除前

  23. 23

    Ruby on Rails 4和cocoon gem:如何中断对cocoon的删除:删除前

  24. 24

    RSpec / Capybara调试

  25. 25

    Deprecation warning from Capybara

  26. 26

    Capybara Poltergeist ActionCable测试

  27. 27

    RSpec / Capybara调试

  28. 28

    Rails Capybara 无法登录

  29. 29

    CodeIgniter $ this-> form_validation-> set_message

热门标签

归档