class Browsery::PageObjects::Overlay::Base
A Overlay
represents a portion (an element) of a page that is repeated or reproduced multiple times, either on the same page, or across multiple page objects or page modules.
Attributes
driver[R]
Public Class Methods
new(page)
click to toggle source
# File lib/browsery/page_objects/overlay/base.rb, line 16 def initialize(page) @driver = page.driver @page = page # works here but not in initialize of base of page objects # because a page instance is already present when opening an overlay end
Public Instance Methods
find_all(how, what)
click to toggle source
# File lib/browsery/page_objects/overlay/base.rb, line 33 def find_all(how, what) driver.all(how, what) end
find_first(how, what)
click to toggle source
# File lib/browsery/page_objects/overlay/base.rb, line 29 def find_first(how, what) driver.find_element(how, what) end
page_object()
click to toggle source
for overlay that include Utils::OverlayAndWidgetHelper
# File lib/browsery/page_objects/overlay/base.rb, line 25 def page_object @page end
validate!()
click to toggle source
By default, any driver state is accepted for any page. This method should be overridden in subclasses.
# File lib/browsery/page_objects/overlay/base.rb, line 39 def validate! true end
wait(opts = {})
click to toggle source
Explicitly wait for a certain condition to be true:
wait.until { driver.find_element(:css, 'body.tmpl-srp') }
when timeout is not specified, default timeout 5 sec will be used when timeout is larger than 15, max timeout 15 sec will be used
# File lib/browsery/page_objects/overlay/base.rb, line 71 def wait(opts = {}) if !opts[:timeout].nil? && opts[:timeout] > 15 puts "WARNING: #{opts[:timeout]} sec timeout is NOT supported by wait method, max timeout 15 sec will be used instead" opts[:timeout] = 15 end Selenium::WebDriver::Wait.new(opts) end
wait_for_ajax(timeout = 15)
click to toggle source
Wait on all AJAX requests to finish
# File lib/browsery/page_objects/overlay/base.rb, line 61 def wait_for_ajax(timeout = 15) wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all ajax requests to finish").until do driver.execute_script 'return window.jQuery != undefined && jQuery.active == 0' end end
wait_for_dom(timeout = 15)
click to toggle source
Wait for all dom events to load
# File lib/browsery/page_objects/overlay/base.rb, line 44 def wait_for_dom(timeout = 15) uuid = SecureRandom.uuid # make sure body is loaded before appending anything to it wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for body to load").until do is_element_present?(:css, 'body') end driver.execute_script <<-EOS _.defer(function() { $('body').append("<div id='#{uuid}'></div>"); }); EOS wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all dom events to finish").until do is_element_present?(:css, "div[id='#{uuid}']") end end