Class: Domkey::View::PageObject
- Inherits:
-
Object
- Object
- Domkey::View::PageObject
- 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
Instance Attribute Summary
Attributes included from Widgetry::Package
Instance Method Summary collapse
-
#method_missing(message, *args, &block) ⇒ Object
private
delegate to element when element responds to message.
- #options ⇒ Object
-
#respond_to_missing?(message, include_private = false) ⇒ Boolean
private
ruturn true when element.respond_to? message so we can delegate with confidence.
-
#set(value) ⇒ Object
(also: #value=)
Each Semantic PageObject defines what value means for itself.
-
#value ⇒ SemanticValue, Hash{Symbol => SemanticValue}
Each Semantic PageObject defines what value means for itself.
Methods included from Widgetry::Package
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(, *args, &block) if element.respond_to?() element.__send__(, *args, &block) else super end end |
Instance Method Details
#options ⇒ Object
75 76 77 78 |
# File 'lib/domkey/view/page_object.rb', line 75 def return . unless package.respond_to?(:each_pair) Hash[package.map { |key, pageobject| [key, pageobject.] }] 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
93 94 95 |
# File 'lib/domkey/view/page_object.rb', line 93 def respond_to_missing?(, include_private = false) element.respond_to?() || super end |
#set(value) ⇒ Object Also known as: value=
Each Semantic PageObject defines what value means for itself
60 61 62 63 |
# File 'lib/domkey/view/page_object.rb', line 60 def set value return .set value unless value.respond_to?(:each_pair) value.each_pair { |k, v| package.fetch(k).set(v) } end |
#value ⇒ SemanticValue, Hash{Symbol => SemanticValue}
Each Semantic PageObject defines what value means for itself
70 71 72 73 |
# File 'lib/domkey/view/page_object.rb', line 70 def value return .value unless package.respond_to?(:each_pair) Hash[package.map { |key, pageobject| [key, pageobject.value] }] end |