Class: Browsery::PageObjects::Overlay::Base
- Inherits:
-
Object
- Object
- Browsery::PageObjects::Overlay::Base
- Extended by:
- ElementContainer
- Defined in:
- lib/browsery/page_objects/overlay/base.rb
Overview
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.
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #find_all(how, what) ⇒ Object
- #find_first(how, what) ⇒ Object
-
#initialize(page) ⇒ Base
constructor
A new instance of Base.
-
#page_object ⇒ Object
for overlay that include Utils::OverlayAndWidgetHelper.
-
#validate! ⇒ Object
By default, any driver state is accepted for any page.
-
#wait(opts = {}) ⇒ Object
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.
-
#wait_for_ajax(timeout = 15) ⇒ Object
Wait on all AJAX requests to finish.
-
#wait_for_dom(timeout = 15) ⇒ Object
Wait for all dom events to load.
Methods included from ElementContainer
add_to_mapped_items, element, elements, section, sections
Methods included from Utils::OverlayAndWidgetHelper
Methods included from Utils::PageObjectHelper
#connector_is_saucelabs?, #current_page, #is_element_present?, #is_element_present_and_displayed?, #json_save_to_ever_failed, #page, #print_sauce_link, #put_value, #read_yml, #retry_with_count, #take_screenshot, #teardown, #update_sauce_session_name, #update_sauce_session_status, #visual_regression, #wait_for_attribute_to_have_value, #wait_for_element_to_be_present, #wait_for_element_to_display, #with_url_change_wait
Methods included from Utils::Castable
Constructor Details
#initialize(page) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
14 15 16 |
# File 'lib/browsery/page_objects/overlay/base.rb', line 14 def driver @driver end |
Instance Method Details
#find_all(how, what) ⇒ Object
33 34 35 |
# File 'lib/browsery/page_objects/overlay/base.rb', line 33 def find_all(how, what) driver.all(how, what) end |
#find_first(how, what) ⇒ Object
29 30 31 |
# File 'lib/browsery/page_objects/overlay/base.rb', line 29 def find_first(how, what) driver.find_element(how, what) end |
#page_object ⇒ Object
for overlay that include Utils::OverlayAndWidgetHelper
25 26 27 |
# File 'lib/browsery/page_objects/overlay/base.rb', line 25 def page_object @page end |
#validate! ⇒ Object
By default, any driver state is accepted for any page. This method should be overridden in subclasses.
39 40 41 |
# File 'lib/browsery/page_objects/overlay/base.rb', line 39 def validate! true end |
#wait(opts = {}) ⇒ Object
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
71 72 73 74 75 76 77 78 |
# 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) ⇒ Object
Wait on all AJAX requests to finish
61 62 63 64 65 |
# 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) ⇒ Object
Wait for all dom events to load
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |