Module: Waiter

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

Class Method Summary collapse

Class Method Details

.pageObject



137
138
139
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 137

def page
  Capybara.current_session
end

.pending_ajax_requests_numObject



150
151
152
153
154
155
156
# File 'lib/cucumber/pickles/helpers/waiter.rb', line 150

def pending_ajax_requests_num
  req_num = page.evaluate_script("window.activeRequests")
  return req_num if req_num

  stub_xml_http_request(page)
  page.evaluate_script("window.activeRequests")
end

.waitObject



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

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



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

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