Module: Dekiru::Capybara::LegacyHelpers

Defined in:
lib/dekiru/capybara/legacy_helpers.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#finished_all_ajax_requests?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dekiru/capybara/legacy_helpers.rb', line 35

def finished_all_ajax_requests?
  page.evaluate_script('jQuery.active').zero?
end

#wait_for_ajaxObject



31
32
33
# File 'lib/dekiru/capybara/legacy_helpers.rb', line 31

def wait_for_ajax
  wait_until { finished_all_ajax_requests? }
end

#wait_for_event(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dekiru/capybara/legacy_helpers.rb', line 6

def wait_for_event(event)
  page.execute_script(<<~"EOS")
    (function(){
      var eventName = '#{event}';
      window._dekiruCapybaraWaitEvents = window._dekiruCapybaraWaitEvents || {};
      window._dekiruCapybaraWaitEvents[eventName] = 1;
      jQuery(document).one(eventName, function(){window._dekiruCapybaraWaitEvents[eventName] = 0;});
    })();
  EOS
  yield

  script = <<~"EOS"
    (function(){
      var eventName = '#{event}';
      return window._dekiruCapybaraWaitEvents && window._dekiruCapybaraWaitEvents[eventName];
    })();
  EOS
  wait_until do
    result = page.evaluate_script(script)
    raise Error, 'wait_for_event: Missing context. probably moved to another page.' if result.nil?
    result == 0
  end
end