Class: BaseInterface

Inherits:
Object
  • Object
show all
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

ChromeInterface, FirefoxInterface, NullInterface

Constant Summary

Constants included from Utilities

Utilities::DEFAULT_TIMEOUT, Utilities::POLL_SLEEP_TIME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#await, #class_info, #location, #page?, #raise_if_not_page

Constructor Details

#initializeBaseInterface

Returns a new instance of BaseInterface.



13
14
15
# File 'lib/rutl/interface/base_interface.rb', line 13

def initialize
  raise 'Child interface class must set @driver.' if @driver.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rutl/interface/base_interface.rb', line 26

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

#driverObject

Returns the value of attribute driver.



10
11
12
# File 'lib/rutl/interface/base_interface.rb', line 10

def driver
  @driver
end

#pagesObject

Returns the value of attribute pages.



11
12
13
# File 'lib/rutl/interface/base_interface.rb', line 11

def pages
  @pages
end

Instance Method Details

#current_pageObject



22
23
24
# File 'lib/rutl/interface/base_interface.rb', line 22

def current_page
  raise 'define in child classes'
end

#find_page(page) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/rutl/interface/base_interface.rb', line 45

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?



36
37
38
39
40
41
42
43
# File 'lib/rutl/interface/base_interface.rb', line 36

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



17
18
19
20
# File 'lib/rutl/interface/base_interface.rb', line 17

def goto(page)
  raise 'expect Page class' unless page.ancestors.include?(BasePage)
  find_page(page).go_to_here
end

#quitObject



66
67
68
69
70
# File 'lib/rutl/interface/base_interface.rb', line 66

def quit
  @driver.quit
  # Maybe I'm reusing pages from @pages?
  # @pages = []
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/rutl/interface/base_interface.rb', line 61

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



53
54
55
56
57
58
59
# File 'lib/rutl/interface/base_interface.rb', line 53

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