class Workarea::SystemTest

Public Instance Methods

javascript?() click to toggle source
# File lib/workarea/system_test.rb, line 146
def javascript?
  Capybara.current_driver == Capybara.javascript_driver
end
reset_window_size() click to toggle source

Resets the dimensions of the testing browser

# File lib/workarea/system_test.rb, line 137
def reset_window_size
  return unless javascript?

  page.driver.browser.manage.window.resize_to(
    Workarea.config.capybara_browser_width,
    Workarea.config.capybara_browser_height
  )
end
scroll_to_bottom() click to toggle source
# File lib/workarea/system_test.rb, line 150
def scroll_to_bottom
  page.execute_script('window.scrollBy(0, 9999999)')
end
wait_for_iframe() click to toggle source

There is some kind of timing problem around waiting for this iframe that after a few hours we still can't find. This is a hack to keep this passing.

May God have mercy on our souls.

TODO v3.6 Remove this after we stop using an iframe for the admin toolbar

# File lib/workarea/system_test.rb, line 167
def wait_for_iframe
  sleep(0.5)
end
wait_for_xhr(time=Capybara.default_max_wait_time) click to toggle source

Waits until all XHR requests have finished, according to jQuery. Times out according to Capybara's set timeout. Used to solve race conditions between XHR requests and assertions.

# File lib/workarea/system_test.rb, line 109
    def wait_for_xhr(time=Capybara.default_max_wait_time)
      Timeout.timeout(time) do
        loop until finished_all_xhr_requests?
      end
    rescue Timeout::Error => error
      javascript_errors = page.driver.browser.manage.logs.get(:browser).each do |log_entry|
        log_entry.level == 'SEVERE' && /Uncaught/.match?(log_entry.message)
      end
      if javascript_errors.present?
        raise(
          Timeout::Error,
          <<~eos
            Problem:
              JavaScript errors were detected during Workarea::SystemTest#wait_for_xhr.
              You might have an error in an XHR callback.  wait_for_xhr is a test helper
              that checks if there are any unfinished XHR requests.  This is called
              automatically throughout testing in Capybara interactions to ensure
              consistency in test results.
            Errors:
              #{javascript_errors.map(&:message).join("\r")}
          eos
        )
      else
        raise error
      end
    end

Private Instance Methods

finished_all_xhr_requests?() click to toggle source
# File lib/workarea/system_test.rb, line 173
def finished_all_xhr_requests?
  return unless javascript?

  page.evaluate_script("!window['jQuery'] || jQuery.active === 0")
end