Sha256: 186dbf244aea7920db493b2687139d3342cce1f0e97b23b77544dfbb3786cbb4

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

# coding: UTF-8

module ToleranceForSeleniumSyncIssues
  RETRY_ERRORS = %w[Capybara::ElementNotFound Spec::Expectations::ExpectationNotMetError RSpec::Expectations::ExpectationNotMetError Capybara::Poltergeist::ClickFailed Selenium::WebDriver::Error::StaleElementReferenceError Selenium::WebDriver::Error::NoAlertPresentError]

  # This is similiar but not entirely the same as Capybara::Node::Base#wait_until or Capybara::Session#wait_until
  def patiently(seconds=Capybara.default_wait_time, &block)
    old_wait_time = Capybara.default_wait_time
    # dont make nested wait_untils use up all the alloted time
    Capybara.default_wait_time = 0 # for we are a jealous gem
    if page.driver.wait?
      start_time = Time.now
      begin
        block.call
      rescue Exception => e
        raise e unless RETRY_ERRORS.include?(e.class.name)
        raise e if (Time.now - start_time) >= seconds
        sleep(0.05)
        raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Time.now == start_time
        retry
      end
    else
      block.call
    end
  ensure
    Capybara.default_wait_time = old_wait_time
  end
end

World(ToleranceForSeleniumSyncIssues)

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
spreewald-0.9.0 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.6 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.5 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.4 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.3 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.2 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.1 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.8.0 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.7.0 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.7 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.6 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.5 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.4 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.3 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.2 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.1 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.6.0 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.5.20 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.5.19 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
spreewald-0.5.18 lib/spreewald_support/tolerance_for_selenium_sync_issues.rb