Class: MiniAutobot::PageObjects::Overlay::Base

Inherits:
Object
  • Object
show all
Includes:
Utils::Castable, Utils::OverlayAndWidgetHelper, Utils::PageObjectHelper
Defined in:
lib/mini_autobot/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

Instance Method Summary collapse

Methods included from Utils::OverlayAndWidgetHelper

#get_overlay!, #get_widgets!

Methods included from Utils::PageObjectHelper

#connector_is_saucelabs?, #is_element_present?, #is_element_present_and_displayed?, #page, #print_sauce_link, #put_value, #read_yml, #retry_with_count, #save_to_ever_failed, #take_screenshot, #teardown, #update_sauce_session

Methods included from Utils::Castable

#cast, #cast_any, included

Constructor Details

#initialize(page) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 15

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

#driverObject (readonly)

Returns the value of attribute driver.



13
14
15
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 13

def driver
  @driver
end

Instance Method Details

#page_objectObject

for overlay that include Utils::OverlayAndWidgetHelper



24
25
26
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 24

def page_object
  @page
end

#validate!Object

By default, any driver state is accepted for any page. This method should be overridden in subclasses.



30
31
32
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 30

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



62
63
64
65
66
67
68
69
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 62

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



52
53
54
55
56
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 52

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mini_autobot/page_objects/overlay/base.rb', line 35

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