Class: Domkey::View::PageObject

Inherits:
Object
  • Object
show all
Includes:
Widgetry::Package
Defined in:
lib/domkey/view/page_object.rb

Overview

PageObject represents an semantically essential area in a View It is an object that responds to set and value as the main way of sending data to it. it is composed of one or more watir elements. PageObject encapuslates the widgetry of DOM elements to provide semantic interfact to the user of the widgetry

Compose PageObject with package and container

What is a container? it’s a proc, a callable object that plays a role of a container for package widgetry container can be one of:

  • browser (default)

  • a pageobject

What is package? it’s a proc of DOM elements widgetry that can be found inside the container package can be one of the following:

- definition of single watir element i.e. `-> { text_field(:id, 'foo')}`
- a pageobject i.e. previously instantiated definition
- hash where key defines subelement and value a definition or pageobject

Usage: Clients would not usually instantate this class. A client class which acts as a View would use a :dom factory method to create PageObjects Example:

class MyView
  include Domkey::View

  dom(:headline) { text_field(id:, 'some_desc_text') }

  def property
    PropertyPanel.new browser.div(id: 'container')
  end
end

class PropertyPanel
  include Domkey::View
  dom(:headline) { text_field(class: 'headline_for_house') }
end

view = MyView.new
view.headline.set 'HomeAway Rules!'
view.value #=> returns 'HomeAway Rules!'
view.property.headline.set 'Awesome Vactaion Home'
view.property.headline.value #=> returns 'Awesome Vaction Home'

Direct Known Subclasses

SelectList

Instance Attribute Summary

Attributes included from Widgetry::Package

#container, #package

Instance Method Summary collapse

Methods included from Widgetry::Package

#element, #initialize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(message, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

delegate to element when element responds to message



83
84
85
86
87
88
89
# File 'lib/domkey/view/page_object.rb', line 83

def method_missing(message, *args, &block)
  if element.respond_to?(message)
    element.__send__(message, *args, &block)
  else
    super
  end
end

Instance Method Details

#optionsObject



75
76
77
78
# File 'lib/domkey/view/page_object.rb', line 75

def options
  return widgetry_dispatcher.options unless package.respond_to?(:each_pair)
  Hash[package.map { |key, pageobject| [key, pageobject.options] }]
end

#respond_to_missing?(message, include_private = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

ruturn true when element.respond_to? message so we can delegate with confidence

Returns:

  • (Boolean)


93
94
95
# File 'lib/domkey/view/page_object.rb', line 93

def respond_to_missing?(message, include_private = false)
  element.respond_to?(message) || super
end

#set(value) ⇒ Object Also known as: value=

Each Semantic PageObject defines what value means for itself

Parameters:

  • Delegated (SemanticValue)

    to WebdriverElement and we expect it to respond to set



60
61
62
63
# File 'lib/domkey/view/page_object.rb', line 60

def set value
  return widgetry_dispatcher.set value unless value.respond_to?(:each_pair)
  value.each_pair { |k, v| package.fetch(k).set(v) }
end

#valueSemanticValue, Hash{Symbol => SemanticValue}

Each Semantic PageObject defines what value means for itself

Returns:

  • (SemanticValue)

    delegated to WebdriverElement and we expect it to respond to value message

  • (Hash{Symbol => SemanticValue})


70
71
72
73
# File 'lib/domkey/view/page_object.rb', line 70

def value
  return widgetry_dispatcher.value unless package.respond_to?(:each_pair)
  Hash[package.map { |key, pageobject| [key, pageobject.value] }]
end