Class: BaseInterface
- Inherits:
-
Object
- Object
- BaseInterface
- Includes:
- Utilities
- Defined in:
- lib/rutl/interface/base_interface.rb
Overview
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
-
#camera ⇒ Object
readonly
Returns the value of attribute camera.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#pages ⇒ Object
Returns the value of attribute pages.
Instance Method Summary collapse
- #current_page ⇒ Object
- #find_page(page) ⇒ Object
-
#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
-
#initialize ⇒ 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 ⇒ BaseInterface
Returns a new instance of BaseInterface.
14 15 16 17 18 19 20 |
# File 'lib/rutl/interface/base_interface.rb', line 14 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('Interface', '') @camera = ScreenCam.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
32 33 34 35 36 37 38 |
# File 'lib/rutl/interface/base_interface.rb', line 32 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 (readonly)
Returns the value of attribute camera.
11 12 13 |
# File 'lib/rutl/interface/base_interface.rb', line 11 def camera @camera end |
#driver ⇒ Object
Returns the value of attribute driver.
10 11 12 |
# File 'lib/rutl/interface/base_interface.rb', line 10 def driver @driver end |
#pages ⇒ Object
Returns the value of attribute pages.
12 13 14 |
# File 'lib/rutl/interface/base_interface.rb', line 12 def pages @pages end |
Instance Method Details
#current_page ⇒ Object
28 29 30 |
# File 'lib/rutl/interface/base_interface.rb', line 28 def current_page raise 'define in child classes' end |
#find_page(page) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rutl/interface/base_interface.rb', line 51 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?
42 43 44 45 46 47 48 49 |
# File 'lib/rutl/interface/base_interface.rb', line 42 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?(@driver) end false end |
#goto(page) ⇒ Object
22 23 24 25 26 |
# File 'lib/rutl/interface/base_interface.rb', line 22 def goto(page) raise 'expect Page class' unless page.ancestors.include?(BasePage) find_page(page).go_to_here @camera.screenshot end |
#quit ⇒ Object
72 73 74 75 76 |
# File 'lib/rutl/interface/base_interface.rb', line 72 def quit @driver.quit # Maybe I'm reusing pages from @pages? # @pages = [] end |
#respond_to_missing?(*args) ⇒ Boolean
67 68 69 70 |
# File 'lib/rutl/interface/base_interface.rb', line 67 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
59 60 61 62 63 64 65 |
# File 'lib/rutl/interface/base_interface.rb', line 59 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 |