Class: BaseInterface
- Inherits:
-
Object
- Object
- BaseInterface
- Includes:
- Utilities
- Defined in:
- lib/rutl/interface/base_interface.rb
Overview
I might need to consider renaming these. The *interface classes lie between Browser and the webdriver-level classes.
Direct Known Subclasses
Constant Summary
Constants included from Utilities
Utilities::DEFAULT_TIMEOUT, Utilities::POLL_SLEEP_TIME
Instance Attribute Summary collapse
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#interface ⇒ Object
Returns the value of attribute interface.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #current_page ⇒ Object
- #current_url ⇒ Object
- #find_page(page, raise_on_fail = false) ⇒ Object
-
#find_state(target_states) ⇒ Object
TODO: Is this needed? I not only find the page but also make sure the urls match.
- #goto(input) ⇒ Object
-
#initialize(pages:) ⇒ BaseInterface
constructor
A new instance of BaseInterface.
- #method_missing(method, *args, &block) ⇒ Object
- #quit ⇒ Object
- #respond_to_missing?(*args) ⇒ Boolean
- #wait_for_transition(target_states) ⇒ Object
Methods included from Utilities
#await, #class_info, #location, #page?, #raise_if_not_page
Constructor Details
#initialize(pages:) ⇒ BaseInterface
Returns a new instance of BaseInterface.
18 19 20 21 22 |
# File 'lib/rutl/interface/base_interface.rb', line 18 def initialize(pages:) @pages = pages raise 'Child classes must implement @driver.' unless defined? @driver @pages.each { |p| p.driver = @driver } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rutl/interface/base_interface.rb', line 36 def method_missing(method, *args, &block) result = if args.empty? current_page.send(method) else current_page.send(method, *args, &block) end raise interface.to_s if interface.nil? raise result.to_s unless defined? result # result.interface begin result.interface = interface rescue NoMethodError raise NoMethodError, "METHOD NOT FOUND: #{method}" end result end |
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
15 16 17 |
# File 'lib/rutl/interface/base_interface.rb', line 15 def driver @driver end |
#interface ⇒ Object
Returns the value of attribute interface.
16 17 18 |
# File 'lib/rutl/interface/base_interface.rb', line 16 def interface @interface end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
14 15 16 |
# File 'lib/rutl/interface/base_interface.rb', line 14 def pages @pages end |
Instance Method Details
#current_page ⇒ Object
32 33 34 |
# File 'lib/rutl/interface/base_interface.rb', line 32 def current_page raise 'OVERRIDE IN CHILDREN' end |
#current_url ⇒ Object
10 11 12 |
# File 'lib/rutl/interface/base_interface.rb', line 10 def current_url current_page.url end |
#find_page(page, raise_on_fail = false) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/rutl/interface/base_interface.rb', line 64 def find_page(page, raise_on_fail = false) @pages.each do |p| # page is a Page class return p if page?(page) && p.class == page # or a String, possibly URL return p if String == page.class && page == p.url end raise "Page \"#{page}\" not found in pages #{@pages}" if raise_on_fail 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?
54 55 56 57 58 59 60 61 62 |
# File 'lib/rutl/interface/base_interface.rb', line 54 def find_state(target_states) target_states.each do |state| next unless state.url == current_page.url page = find_page(state, true) return page if page.loaded? end raise current_page.to_s if current_page.class == InternetLoggedInPage false end |
#goto(input) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rutl/interface/base_interface.rb', line 24 def goto(input) # TODO: KLUDGY. Fix. Modifier if usage bombs here. *shrug* @driver.interface = @interface if @interface.class.to_s == 'NullInterface' input = find_page(input) unless input.methods.include?(:url) @driver.navigate.to input.url end |
#quit ⇒ Object
87 88 89 90 |
# File 'lib/rutl/interface/base_interface.rb', line 87 def quit @driver.quit @pages = [] end |
#respond_to_missing?(*args) ⇒ Boolean
82 83 84 85 |
# File 'lib/rutl/interface/base_interface.rb', line 82 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
74 75 76 77 78 79 80 |
# File 'lib/rutl/interface/base_interface.rb', line 74 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 |