Class: TransactionalCapybara::AjaxHelpers::PageWaiting

Inherits:
Object
  • Object
show all
Defined in:
lib/transactional_capybara/ajax_helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ PageWaiting

Returns a new instance of PageWaiting.


4
5
6
# File 'lib/transactional_capybara/ajax_helpers.rb', line 4

def initialize(page)
  @page = page
end

Instance Method Details

#finished_ajax_requests?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/transactional_capybara/ajax_helpers.rb', line 22

def finished_ajax_requests?
  ( angular_requests + jquery_requests ).zero?
end

#finished_all_ajax_requests?Boolean

Returns:

  • (Boolean)

12
13
14
15
16
17
18
19
20
# File 'lib/transactional_capybara/ajax_helpers.rb', line 12

def finished_all_ajax_requests?
  capybara_sessions.all? do |name, session|
    if is_session_touched?(session)
      PageWaiting.new(session).finished_ajax_requests?
    else
      true
    end
  end
end

#wait_for_ajaxObject


8
9
10
# File 'lib/transactional_capybara/ajax_helpers.rb', line 8

def wait_for_ajax
  wait_until { finished_all_ajax_requests? }
end

#wait_until(timeout = default_timeout) ⇒ Object

TODO: timeout each individual session


27
28
29
30
31
32
33
34
35
# File 'lib/transactional_capybara/ajax_helpers.rb', line 27

def wait_until(timeout=default_timeout)
  Timeout.timeout(timeout) do
    until yield
      sleep(0.01)
    end
  end
rescue Timeout::Error
  # Oh well, hopefully it finished!
end