I am currently looking for a software/web development job preferably as a Rails-based developer.
Please email me at weston@westonganger.com. Thanks in advance for any leads!

Testing Chosen Selects With Capybara And Rails

Posted by Weston Ganger

I was having trouble using my chosen selects when starting out using Capybara. Turns out you need to add a couple helper methods to your test helper file.

# test_helper.rb

def select_first_from_chosen(from) # `from` is any selector find_field allows
  field = find_field(from, visible: false)
  first("##{field[:id]}_chosen ul.chosen-results li").click

def select_from_chosen(item_text, options)
  field = find_field(options[:from], visible: false)
  find("##{field[:id]}_chosen ul.chosen-results li", text: item_text).click

You can then use these methods as alternative to select method of Capybara.


select_from_chosen('Vancouver', from: '#site_id')

Related External Links:

Article Topic:Software Development - Rails

Date:December 08, 2016

Recommended Posts