Created
May 8, 2012 00:38
-
-
Save twe4ked/2631690 to your computer and use it in GitHub Desktop.
Testing chosen with RSpec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_chosen(selector, search) | |
page.execute_script "jQuery('#{selector}').click();" | |
find('div.chzn-search input').set search | |
end | |
def select_from_chosen(selector, name) | |
page.execute_script "jQuery('#{selector}').click();" | |
page.execute_script "jQuery(\".chzn-results .active-result:contains('#{name}')\").click();" | |
wait_for_ajax | |
end | |
def visible_in_chosen(*args) | |
within '.chzn-drop' do | |
args.each do |text| | |
page.should have_css('li', :text => text) | |
end | |
end | |
end | |
def not_visible_in_chosen(*args) | |
within '.chzn-drop' do | |
args.each do |text| | |
page.should have_no_css('li', :text => text) | |
end | |
end | |
end | |
def wait_for_ajax | |
if Capybara.current_driver == :selenium | |
delay = Capybara.default_wait_time/100.0 | |
100.times do | |
break if evaluate_script('jQuery.active').to_i == 0 | |
sleep delay | |
end | |
unless evaluate_script('jQuery.active').to_i == 0 | |
raise "Giving up waiting for AJAX to complete after #{Capybara.default_wait_time} seconds" | |
end | |
end | |
end |
how can I be sure that the result got chosen when I do select_from_chosen ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code was very helpful, but I needed to change the click event, for a mouseup event, something like:
page.execute_script "jQuery(".chzn-results .active-result:contains('#{name}')").trigger('mouseup');"