Class: RUTL::Interface::Base
- Inherits:
-
Object
- Object
- RUTL::Interface::Base
- Includes:
- Utilities
- Defined in:
- lib/rutl/interface/base.rb
Overview
I might need to consider renaming these. The *interface classes lie between Browser and the webdriver-level classes.
Constant Summary
Constants included from Utilities
Utilities::DEFAULT_TIMEOUT, Utilities::POLL_SLEEP_TIME
Instance Attribute Summary collapse
-
#camera ⇒ Object
RUTL::Camera.
-
#driver ⇒ Object
RUTL::Driver.
-
#pages ⇒ Object
Array of all RUTL::Page classes.
Instance Method Summary collapse
-
#current_page ⇒ Object
Should define in children; raises here.
-
#find_page(page) ⇒ Object
Attempts to find page by class or url.
-
#find_state(target_states) ⇒ Object
TODO: Is this needed? I not only find the page but also make sure the urls match.
-
#goto(page) ⇒ Object
Attempts to navigate to the page.
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #method_missing(method, *args, &block) ⇒ Object
- #quit ⇒ Object
- #respond_to_missing?(*args) ⇒ Boolean
-
#wait_for_transition(target_states) ⇒ Object
Calls the polling utility mathod await() with a lambda trying to find the next state, probably a Page class.
Methods included from Utilities
#await, #class_info, #location, #page?
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 29 |
# File 'lib/rutl/interface/base.rb', line 23 def initialize raise 'Child interface class must set @driver.' if @driver.nil? # base_name avoids collisions when unning the same tests with # different browsers. name = self.class.to_s.sub('RUTL::Interface', '') @camera = Camera.new(@driver, base_name: name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rutl/interface/base.rb', line 45 def method_missing(method, *args, &block) if args.empty? current_page.send(method) else current_page.send(method, *args, &block) end end |
Instance Attribute Details
#camera ⇒ Object
RUTL::Camera
18 19 20 |
# File 'lib/rutl/interface/base.rb', line 18 def camera @camera end |
#driver ⇒ Object
RUTL::Driver
15 16 17 |
# File 'lib/rutl/interface/base.rb', line 15 def driver @driver end |
#pages ⇒ Object
Array of all RUTL::Page classes
21 22 23 |
# File 'lib/rutl/interface/base.rb', line 21 def pages @pages end |
Instance Method Details
#current_page ⇒ Object
Should define in children; raises here. Should return the current page class.
41 42 43 |
# File 'lib/rutl/interface/base.rb', line 41 def current_page raise 'define in child classes' end |
#find_page(page) ⇒ Object
Attempts to find page by class or url.
65 66 67 68 69 70 71 |
# File 'lib/rutl/interface/base.rb', line 65 def find_page(page) @pages.each do |p| return p if page?(page) && p.class == page return p if String == page.class && page == p.url end raise "Page \"#{page}\" not found in pages #{@pages}" end |
#find_state(target_states) ⇒ Object
TODO: Is this needed? I not only find the page but also make sure the urls match. Even though that’s what finding pages means?
55 56 57 58 59 60 61 62 |
# File 'lib/rutl/interface/base.rb', line 55 def find_state(target_states) target_states.each do |state| next unless state.url == current_page.url page = find_page(state) return page if page.loaded? end false end |
#goto(page) ⇒ Object
Attempts to navigate to the page. Takes screenshot if successful.
33 34 35 36 37 |
# File 'lib/rutl/interface/base.rb', line 33 def goto(page) raise 'expect Page class' unless page?(page) find_page(page).go_to_here @camera.screenshot end |
#quit ⇒ Object
88 89 90 |
# File 'lib/rutl/interface/base.rb', line 88 def quit @driver.quit end |
#respond_to_missing?(*args) ⇒ Boolean
83 84 85 86 |
# File 'lib/rutl/interface/base.rb', line 83 def respond_to_missing?(*args) # This can't be right. Figure it out later. current_page.respond_to?(*args) end |
#wait_for_transition(target_states) ⇒ Object
Calls the polling utility mathod await() with a lambda trying to find the next state, probably a Page class.
75 76 77 78 79 80 81 |
# File 'lib/rutl/interface/base.rb', line 75 def wait_for_transition(target_states) # # TODO: Should also see if there are other things to wait for. # I don't think this is doing page load time. # await -> { find_state target_states } end |