Module: SeleniumRecord::Waits

Included in:
Base
Defined in:
lib/selenium_record/waits.rb

Overview

Helpers to make easy waiting for something to happen

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_WAITING_TIME =
20

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/selenium_record/waits.rb', line 7

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#wait_displayed(locator, opts = {}) ⇒ Object

Wait selenium execution until the element is displayed

Parameters:

  • locator (Hash)

    contains unique value where the key is the locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)



32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object

Waits until the ‘model_view’ corresponding to the model is completely visible

Parameters:

  • model (PORO)

    plain old ruby object with a related ‘model_view’



47
48
49
50
# 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_hidden(locator) ⇒ Object

Waits until the ‘model_view’ corresponding to the model is completely hidden

Parameters:

  • locator (Hash)

    contains unique value where the key is the locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/selenium_record/waits.rb', line 57

def wait_hidden(locator)
  self.class.wait_for do
    begin
      finder = root_el || browser
      element = finder.find_element(locator)
      !element.displayed?
    rescue Selenium::WebDriver::Error::StaleElementReferenceError
      true
    end
  end
end

#wait_js_inactive(seconds = DEFAULT_WAITING_TIME) ⇒ Object

Wait selenium execution until no ajax request is pending in the browser

Parameters:

  • seconds (Integer) (defaults to: DEFAULT_WAITING_TIME)

    number of seconds to wait



13
14
15
16
17
18
19
# 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_loadObject



21
22
23
24
25
26
# 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