Class: RUTL::Element::ElementContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rutl/element/element_context.rb

Overview

The context passed around to all elements. What they need to know outside of themselves to function.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destinations: nil, interface: nil, selectors: []) ⇒ ElementContext

Returns a new instance of ElementContext.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rutl/element/element_context.rb', line 17

def initialize(destinations: nil, interface: nil, selectors: [])
  unless destinations.nil? || destinations.class == Array
    # Should check each destination to make sure it's a
    # View or a _____, too.
    raise 'destination must be an Array of destinations or nil.'
  end
  @destinations = destinations || []
  unless interface.nil? || interface.is_a?(RUTL::Interface::Base)
    raise "#{interface.class}: #{interface} " \
          'must be an Interface::* class.'
  end
  @interface = interface
  @selectors = selectors
end

Instance Attribute Details

#destinationsObject

Nil. Or an Array. One would hope an Array of states. But I’m not checking.



10
11
12
# File 'lib/rutl/element/element_context.rb', line 10

def destinations
  @destinations
end

#interfaceObject

Nil. Or a RUTL::Interface::Base.



12
13
14
# File 'lib/rutl/element/element_context.rb', line 12

def interface
  @interface
end

#selectorsObject

An Arrray, maybe empty and maybe an array of selectors. TODO: This should be a hash.



15
16
17
# File 'lib/rutl/element/element_context.rb', line 15

def selectors
  @selectors
end

Instance Method Details

#find_element(type = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rutl/element/element_context.rb', line 32

def find_element(type = nil)
  type ||= @selectors.first.first
  # @interface.driver.find_element(type, @selectors[type])
  # Should be this, but apparently @interface.driver is being overwritten
  # (or not written to) and it doesn't work. Using $application does. :-(
  $application.interface.driver.find_element(type, @selectors[type])
end