Class: NullDriverPageElement

Inherits:
Object
  • Object
show all
Defined in:
lib/rutl/driver/null_driver_page_element.rb

Overview

This fakes all page 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) ⇒ NullDriverPageElement

Returns a new instance of NullDriverPageElement.



14
15
16
17
18
# File 'lib/rutl/driver/null_driver_page_element.rb', line 14

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

Instance Attribute Details

#contextObject

Returns the value of attribute context.



8
9
10
# File 'lib/rutl/driver/null_driver_page_element.rb', line 8

def context
  @context
end

Class Method Details

.clear_variablesObject



10
11
12
# File 'lib/rutl/driver/null_driver_page_element.rb', line 10

def self.clear_variables
  @@variables = {}
end

Instance Method Details

#attribute(attr) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/rutl/driver/null_driver_page_element.rb', line 30

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

#clearObject



39
40
41
# File 'lib/rutl/driver/null_driver_page_element.rb', line 39

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

#clickObject



47
48
49
50
# File 'lib/rutl/driver/null_driver_page_element.rb', line 47

def click
  # nop
  # Called by ClickToChangeStateMixin like Selenium driver.click
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 pages could change underneath us. For text fields in the null browser, though, we want to preserve the values across calls, letting us write and then read.



25
26
27
28
# File 'lib/rutl/driver/null_driver_page_element.rb', line 25

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

#this_cssObject



43
44
45
# File 'lib/rutl/driver/null_driver_page_element.rb', line 43

def this_css
  self
end