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
-
#wait_displayed(locator, opts = {}) ⇒ Object
Wait selenium execution until the element is displayed.
-
#wait_fade_in(model) ⇒ Object
Waits until the ‘model_view’ corresponding to the model is completely visible.
-
#wait_hidden(locator) ⇒ Object
Waits until the ‘model_view’ corresponding to the model is completely hidden.
-
#wait_js_inactive(seconds = DEFAULT_WAITING_TIME) ⇒ Object
Wait selenium execution until no ajax request is pending in the browser.
- #wait_page_load ⇒ Object
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
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
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
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
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_load ⇒ Object
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 |