module SeleniumRecord::Waits
Helpers to make easy waiting for something to happen
Constants
- DEFAULT_WAITING_TIME
Public Class Methods
included(base)
click to toggle source
# File lib/selenium_record/waits.rb, line 7 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
wait_displayed(locator, opts = {})
click to toggle source
Wait selenium execution until the element is displayed @param locator [Hash] contains unique {key: value} where the key is the
locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)
# File lib/selenium_record/waits.rb, line 32 def wait_displayed(locator, opts = {}) klass = self.class klass.wait_for(klass.seconds_for(opts)) do begin evaluate_displayed(locator) rescue Selenium::WebDriver::Error::StaleElementReferenceError lookup unless parent_el false end end end
wait_fade_in(model)
click to toggle source
Waits
until the ‘model_view’ corresponding to the model is completely visible @param model plain old ruby object with a related ‘model_view’
# File lib/selenium_record/waits.rb, line 47 def wait_fade_in(model) web_el = view_for(model).root_el self.class.wait_for { web_el.css_value('opacity').to_i == 1 } end
wait_js_inactive(seconds = DEFAULT_WAITING_TIME) { || ... }
click to toggle source
Wait selenium execution until no ajax request is pending in the browser @param seconds [Integer] number of seconds to wait
# File lib/selenium_record/waits.rb, line 13 def wait_js_inactive(seconds = DEFAULT_WAITING_TIME) klass = self.class yield if block_given? klass.wait_for(seconds) do browser.execute_script(klass.js_inactive_script) == 0 end end
wait_page_load()
click to toggle source
# File lib/selenium_record/waits.rb, line 21 def wait_page_load self.class.wait_for do browser.execute_script('return document.readyState;') == 'complete' end load_dom end
Private Instance Methods
evaluate_displayed(locator)
click to toggle source
@return element [Selenium::WebDriver::Element] if the element is visible.
Otherwise returns nil.
# File lib/selenium_record/waits.rb, line 73 def evaluate_displayed(locator) finder = root_el || browser element = finder.find_element(locator) element if element.displayed? end