Class: RUTL::Interface::Base

Inherits:
Object
  • Object
show all
Includes:
CheckView, Waiter
Defined in:
lib/rutl/interface/base.rb

Overview

I might need to consider renaming these. The *interface classes lie between Application and the webdriver-level classes.

Direct Known Subclasses

Browser, WindowsApp

Constant Summary

Constants included from Waiter

Waiter::DEFAULT_TIMEOUT, Waiter::POLL_SLEEP_TIME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Waiter

#await

Methods included from CheckView

#view?

Constructor Details

#initializeBase

Returns a new instance of Base.



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

def initialize
  raise 'Child interface class must set @driver.' if @driver.nil?
  # base_name avoids collisions when unning the same tests with
  # different applications
  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



47
48
49
50
51
52
53
# File 'lib/rutl/interface/base.rb', line 47

def method_missing(method, *args, &block)
  if args.empty?
    current_view.send(method)
  else
    current_view.send(method, *args, &block)
  end
end

Instance Attribute Details

#cameraObject

RUTL::Camera



20
21
22
# File 'lib/rutl/interface/base.rb', line 20

def camera
  @camera
end

#driverObject

RUTL::Driver



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

def driver
  @driver
end

#viewsObject

Array of all RUTL::View classes



23
24
25
# File 'lib/rutl/interface/base.rb', line 23

def views
  @views
end

Instance Method Details

#current_viewObject

Should define in children; raises here. Should return the current view class.



43
44
45
# File 'lib/rutl/interface/base.rb', line 43

def current_view
  raise 'define in child classes'
end

#find_state(target_states) ⇒ Object

TODO: Is this needed? I not only find the view but also make sure the urls match. Even though that’s what finding views means?



57
58
59
60
61
62
63
64
# File 'lib/rutl/interface/base.rb', line 57

def find_state(target_states)
  target_states.each do |state|
    next unless state.url == current_view.url
    view = find_view(state)
    return view if view.loaded?
  end
  false
end

#find_view(view) ⇒ Object

Attempts to find view by class or url.



67
68
69
70
71
72
73
# File 'lib/rutl/interface/base.rb', line 67

def find_view(view)
  @views.each do |p|
    return p if view?(view) && p.class == view
    return p if String == view.class && view == p.url
  end
  raise "View \"#{view}\" not found in views #{@views}"
end

#goto(view) ⇒ Object

Attempts to navigate to the view. Takes screenshot if successful.



35
36
37
38
39
# File 'lib/rutl/interface/base.rb', line 35

def goto(view)
  raise 'expect View class' unless view?(view)
  find_view(view).go_to_here
  @camera.screenshot
end

#quitObject



90
91
92
# File 'lib/rutl/interface/base.rb', line 90

def quit
  @driver.quit
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/rutl/interface/base.rb', line 85

def respond_to_missing?(*args)
  # This can't be right. Figure it out later.
  current_view.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 View class.



77
78
79
80
81
82
83
# File 'lib/rutl/interface/base.rb', line 77

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 view load time.
  #
  await -> { find_state target_states }
end