module EDSL::PageObject::AJAX

Public Instance Methods

wait_for_ajax(timeout = 30, message = nil) click to toggle source

Wait until there are no pending ajax requests. This requires you to set the javascript framework in advance.

@param [Numeric] the amount of time to wait for the block to return true. @param [String] the message to include with the error if we exceed the timeout duration.

# File lib/edsl/page_object/ajax_support.rb, line 89
def wait_for_ajax(timeout = 30, message = nil)
  end_time = ::Time.now + timeout
  until ::Time.now > end_time
    begin
      return if browser.execute_script(::EDSL::PageObject::JavascriptFrameworkFacade.pending_requests) == 0
    rescue Selenium::WebDriver::Error::UnknownError, Selenium::WebDriver::Error::JavascriptError
    end
    sleep 0.5
  end
  message = "Timed out waiting for ajax requests to complete" unless message
  raise message
end