Class: RUTL::Element::NullElement

Inherits:
Object
  • Object
show all
Defined in:
lib/rutl/null_driver/null_element.rb

Overview

This fakes all view elements when used with the null driver. It’s a dirty way to avoid modeling all of what a driver talks to.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, _type, location) ⇒ NullElement

Returns a new instance of NullElement.



16
17
18
19
20
# File 'lib/rutl/null_driver/null_element.rb', line 16

def initialize(context, _type, location)
  @@variables ||= {}
  @context = context
  @location = location
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/rutl/null_driver/null_element.rb', line 10

def context
  @context
end

Class Method Details

.clear_variablesObject



12
13
14
# File 'lib/rutl/null_driver/null_element.rb', line 12

def self.clear_variables
  @@variables = {}
end

Instance Method Details

#attribute(attr) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rutl/null_driver/null_element.rb', line 32

def attribute(attr)
  case attr.to_sym
  when :value
    @@variables[@location] || ''
  else
    raise ArgumentError, "Attribute unknown: #{attr}"
  end
end

#clearObject



41
42
43
# File 'lib/rutl/null_driver/null_element.rb', line 41

def clear
  @@variables[@location] = ''
end

#clickObject

Placeholder - NOP Called by RUTL::Element::ClickToChangeStateMixin like Selenium driver.click



52
# File 'lib/rutl/null_driver/null_element.rb', line 52

def click; end

#find_elementObject



45
46
47
# File 'lib/rutl/null_driver/null_element.rb', line 45

def find_element
  self
end

#send_keys(string) ⇒ Object

@@string is a class variable because this framework creates new instances of each element every time it accesses them. This is good behavior by default because views could change underneath us. For text fields in the null application, though, we want to preserve the values across calls, letting us write and then read.



27
28
29
30
# File 'lib/rutl/null_driver/null_element.rb', line 27

def send_keys(string)
  init = @@variables[@location] || ''
  @@variables[@location] = init + string
end