Created
February 20, 2012 23:14
-
-
Save dnagir/1872195 to your computer and use it in GitHub Desktop.
Capybara/Cucumber AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UtilitySteps | |
def wait_for_page_load | |
page.wait_until do | |
if Capybara.current_driver != :rack_test | |
page.has_css?('body.dom-loaded') and !has_pending_ajax_request? | |
else | |
true | |
end | |
end | |
end | |
def has_pending_ajax_request? | |
# http://stackoverflow.com/questions/3148225/jquery-active-function | |
active_requests = page.evaluate_script("jQuery.active") | |
active_requests.should_not be_nil # This will be jQuery.ajax.active in the future jQuery versions | |
active_requests > 0 | |
end | |
def company_by_name_or_current(name) | |
name = name.to_s.strip | |
if name.blank? | |
retrieve_current_company | |
else | |
Company.find_by_name!(name) | |
end | |
end | |
def within_content(&block) | |
page.within('body .main-content', &block) | |
end | |
end | |
World UtilitySteps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment