diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index cbd0bae..aaf69f4 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -18,16 +18,44 @@ module Webrat @selenium.get_html_source end - def clicks_button(button_text = nil) + def clicks_button(button_text = nil, options = {}) + button_text, options = nil, button_text if button_text.is_a?(Hash) && options == {} button_text ||= '*' @selenium.click("button=#{button_text}") - @selenium.wait_for_page_to_load() + wait_for_result(options[:wait]) end - def clicks_link(link_text) - @selenium.click("webratlink=#{Regexp.escape(link_text)}") - @selenium.wait_for_page_to_load() + def clicks_link(link_text, options = {}) + @selenium.click("webratlink=#{link_text}") + wait_for_result(options[:wait]) end + + def wait_for_result(wait_type) + if wait_type == :ajax + wait_for_ajax + elsif wait_type == :effects + wait_for_effects + else + wait_for_page_to_load + end + end + + def wait_for_page_to_load(timeout = 15000) + @selenium.wait_for_page_to_load(timeout) + end + + def wait_for_ajax(timeout = 15000) + @selenium.wait_for_condition "window.Ajax.activeRequestCount == 0", timeout + end + + def wait_for_effects(timeout = 15000) + @selenium.wait_for_condition "window.Effect.Queue.size() == 0", timeout + end + + def wait_for_ajax_and_effects + wait_for_ajax + wait_for_effects + end def selects(option_text, options = {}) id_or_name_or_label = options[:from]