Sha256: 26e93becbc9fbfb40c31769e0af8b631ce65dca3e463279ae1142d93dd64ba22

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'rutl/interface/elements/element_context'

#
# 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.
#
class NullDriverPageElement
  attr_accessor :context

  def self.clear_variables
    @@variables = {}
  end

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

  # @@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.
  def send_keys(string)
    init = @@variables[@location] || ''
    @@variables[@location] = init + string
  end

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

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

  def this_css
    self
  end

  def click
    # nop
    # Called by ClickToChangeStateMixin like Selenium driver.click
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rutl-0.3.0 lib/rutl/driver/null_driver_page_element.rb
rutl-0.2.1 lib/rutl/driver/null_driver_page_element.rb
rutl-0.2.0 lib/rutl/driver/null_driver_page_element.rb