Module: HyperSpec::WaitForAjax
- Defined in:
- lib/hyper-spec/wait_for_ajax.rb
Instance Method Summary collapse
Instance Method Details
#finished_all_ajax_requests? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hyper-spec/wait_for_ajax.rb', line 19 def finished_all_ajax_requests? unless running? sleep 0.25 # this was 1 second, not sure if its necessary to be so long... !running? end rescue Capybara::NotSupportedByDriverError true rescue Exception => e e. == 'jQuery is not defined' end |
#running? ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/hyper-spec/wait_for_ajax.rb', line 12 def running? result = page.evaluate_script('(function(active) { return active; })(jQuery.active)') result && !result.zero? rescue Exception => e puts "wait_for_ajax failed while testing state of jQuery.active: #{e}" end |
#wait_for_ajax ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/hyper-spec/wait_for_ajax.rb', line 3 def wait_for_ajax Timeout.timeout(Capybara.default_max_wait_time) do loop do sleep 0.25 break if finished_all_ajax_requests? end end end |