Module: Waiter

Included in:
Helpers::Main
Defined in:
lib/cucumber/pickles/helpers/waiter.rb

Class Method Summary collapse

Class Method Details

.pageObject



135
136
137
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 135

def page
  Capybara.current_session
end

.pending_ajax_requests_numObject



148
149
150
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 148

def pending_ajax_requests_num
  page.evaluate_script("window.activeRequests")
end

.waitObject



125
126
127
128
129
130
131
132
133
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 125

def wait
  wait_for_ajax

  return unless block_given?

  page.document.synchronize do
    yield
  end
end

.wait_for_ajaxObject

waits for all Ajax requests to finish



142
143
144
145
146
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 142

def wait_for_ajax
  page.document.synchronize do
    pending_ajax_requests_num.zero? || raise(Capybara::ElementNotFound)
  end
end