def wait_for_ajax
counter = 0
while page.evaluate_script(“typeof($) === ‘undefined'”)
counter += 1
print “^”
$stdout.flush
sleep(0.1)
raise “Jquery not initialized after 10 seconds.” if counter >= 100
end
counter = 0
while page.evaluate_script(“typeof($) === ‘undefined'”)
counter += 1
print “^”
$stdout.flush
sleep(0.1)
raise “Jquery not initialized after 10 seconds.” if counter >= 100
end
counter = 0
while page.evaluate_script(“$.active > 0”)
counter += 1
print “_”
$stdout.flush
sleep(0.1)
if counter >= 100
msg = “AJAX request took longer than 10 seconds.”
if page.driver.respond_to?(:console_messages)
msg << ” console messages at time of failure: ” + page.driver.console_messages.inspect
end
raise msg
end
end
end