Module: AePageObjects::Dsl
Instance Method Summary collapse
-
#collection(name, options = {}, &block) ⇒ Object
Defines a collection of elements.
- #element(name, options = {}, &block) ⇒ Object
- #form_for(form_name, options = {}, &block) ⇒ Object
- #inherited(subclass) ⇒ Object
Methods included from InternalHelpers
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
Defines a collection of elements. Blocks are evaluated on the item class used by the collection. collection() defines a method on the class that returns an instance of a collection class which contains instances of the collection’s item class.
Supported signatures are described below.
Signature: (no :is, no :contains, no block)
collection :addresses
Collection class: ::AePageObjects::Collection
Item class: ::AePageObjects::Element
Signature: (no :is, no :contains, block)
collection :addresses do
element :city
element :state
end
Collection class: one-off subclass of ::AePageObjects::Collection
Item class: one-off subclass of ::AePageObjects::Element
Methods defined on item class:
city() # -> instance of ::AePageObjects::Element
state() # -> instance of ::AePageObjects::Element
Signature: (no :is, :contains, no block)
collection :addresses, :contains => Address
Collection class: one-off subclass of ::AePageObjects::Collection
Item class: Address
Signature: (no :is, :contains, block)
collection :addresses, :contains => Address do
element :longitude
element :latitude
end
Collection class: one-off subclass of ::AePageObjects::Collection element
Item class: one-off subclass of Address
Methods defined on item class:
longitude() # -> instance of ::AePageObjects::Element
latitude() # -> instance of ::AePageObjects::Element
Signature: (:is, no :contains, no block)
collection :addresses, :is => AddressList
Collection class: AddressList
Item class: AddressList.item_class
Signature: (:is, no :contains, block)
collection :addresses, :is => AddressList do
element :longitude
element :latitude
end
Collection class: one-off subclass of AddressList
Item class: one-off subclass of AddressList.item_class
Methods defined on item class:
longitude() # -> instance of ::AePageObjects::Element
latitude() # -> instance of ::AePageObjects::Element
Signature: (:is, :contains, no block)
collection :addresses, :is => AddressList, :contains => ExtendedAddress
Collection class: one-off subclass ofAddressList
Item class: ExtendedAddress
Signature: (:is, :contains, block)
collection :addresses, :is => AddressList, :contains => Address do
element :longitude
element :latitude
end
Collection class: one-off subclass of AddressList
Item class: one-off subclass of Address
Methods defined on item class:
longitude() # -> instance of ::AePageObjects::Element
latitude() # -> instance of ::AePageObjects::Element
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ae_page_objects/core/dsl.rb', line 124 def collection(name, = {}, &block) ||= {} # only a collection class is specified or the item class # specified matches the collection's item class if ! block_given? && [:is] && ( [:contains].nil? || [:is].item_class == [:contains] ) return element(name, ) end = .dup # create/get the collection class if [:is] ensure_class_for_param!(:is, [:is], ::AePageObjects::Collection) else [:is] = ::AePageObjects::Collection end item_class = .delete(:contains) || [:is].item_class if block_given? item_class = Class.new(item_class, &block).tap do |new_item_class| new_item_class.element_attributes.merge!(item_class.element_attributes) end end # since we are creating a new item class, we need to subclass the collection class # so we can parameterize the collection class with an item class [:is] = Class.new([:is]) [:is].item_class = item_class element(name, ) end |
#element(name, options = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ae_page_objects/core/dsl.rb', line 15 def element(name, = {}, &block) = .dup [:name] ||= name klass = field_klass(, &block) self.element_attributes[name.to_sym] = klass define_method name do |&block| ElementProxy.new(klass, self, , &block) end klass end |
#form_for(form_name, options = {}, &block) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ae_page_objects/core/dsl.rb', line 159 def form_for(form_name, = {}, &block) ||= {} raise ArgumentError, ":is option not supported" if [:is] raise ArgumentError, "Block required." if block.nil? klass = Class.new(::AePageObjects::Form, &block) = .dup [:is] = klass element(form_name, ) klass.element_attributes.each do |element_name, element_klazz| class_eval <<-RUBY def #{element_name}(*args, &block) #{form_name}.#{element_name}(*args, &block) end RUBY self.element_attributes[element_name] = element_klazz end end |
#inherited(subclass) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/ae_page_objects/core/dsl.rb', line 5 def inherited(subclass) subclass.class_eval do class << self def element_attributes @element_attributes ||= {} end end end end |