lib/testable/element.rb
# Defines an accessor method for an element that allows the "friendly
# name" (identifier) of the element to be proxied to a Watir element
# object that corresponds to the element type. When this identifier
# is referenced, it generates an accessor method for that element
# in the browser. Consider this element definition defined on a class
# with an instance of `page`:
#
#    text_field :username, id: 'username'
#
# This allows:
#
#    page.username.set 'tester'
#
# So any element identifier can be called as if it were a method on
# the interface (class) on which it is defined. Because the method
# is proxied to Watir, you can use the full Watir API by calling
# methods (like `set`, `click`, etc) on the element identifier.
#
# It is also possible to have an element definition like this:
#
#    text_field :password
#
# This would allow access like this:
#
#    page.username(id: 'username').set 'tester'
#
# This approach would lead to the *values variable having an array
# like this: [{:id => 'username'}].
#
# A third approach would be to utilize one element definition within
# the context of another. Consider the following element definitions:
#
#    article :practice, id: 'practice'
#
#    a :page_link do |text|
#      practice.a(text: text)
#    end
#
# This would allow access like this:
#
#    page.page_link('Drag and Drop').click
#
# This approach would lead to the *values variable having an array
# like this: ["Drag and Drop"].
Defines an accessor method for an element that allows the "friendly
name" (identifier) of the element to be proxied to a Watir element
object that corresponds to the element type. When this identifier
is referenced, it generates an accessor method for that element
in the browser. Consider this element definition defined on a class
with an instance of `page`.

text_field :username, id: 'username'

This allows.



So any element identifier can be called as if it were a method on
the interface (class) on which it is defined. Because the method
is proxied to Watir, you can use the full Watir API by calling
methods (like `set`, `click`, etc) on the element identifier.

It is also possible to have an element definition like this.



This would allow access like this.



This approach would lead to the *values variable having an array
like this: [{:id => 'username'}].

A third approach would be to utilize one element definition within
the context of another. Consider the following element definitions.

article :practice, id: 'practice'



This would allow access like this.



This approach would lead to the *values variable having an array
like this: ["Drag and Drop"].
Defines an accessor method for an element that allows the " friendly name " ( identifier ) of the element to be proxied to a Watir element object that corresponds to the element type . When this identifier is referenced it generates an accessor method for that element in the browser . Consider this element definition defined on a class with an instance of ` page ` . text_field : username id : ' username ' This allows . So any element identifier can be called as if it were a method on the interface ( class ) on which it is defined . Because the method is proxied to Watir you can use the full Watir API by calling methods ( like ` set ` ` click ` etc ) on the element identifier . It is also possible to have an element definition like this . This would allow access like this . This approach would lead to the * values variable having an array like this : [ { : id = > ' username ' } ] . A third approach would be to utilize one element definition within the context of another . Consider the following element definitions . article : practice id : ' practice ' This would allow access like this . This approach would lead to the * values variable having an array like this : [ " Drag and Drop " ] .
def define_element_accessor(identifier, *signature, element, &block)
        locators, qualifiers = accessor_aspects(element, signature)
        include(Module.new do
          define_method(identifier.to_s) do |*values|
            if block_given?
              instance_exec(*values, &block)
            else
              locators = values[0] if locators.empty?
              access_element(element, locators, qualifiers)
            end
          end
        end)
      end
def define_element_accessor ( identifier , * signature , element , & block ) locators , qualifiers = accessor_aspects ( element , signature ) include ( Module . new do define_method ( identifier . to_s ) do | * values | if block_given? instance_exec ( * values , & block ) else locators = values [ 0 ] if locators . empty? access_element ( element , locators , qualifiers ) end end end ) end
Defines an accessor method for an element that allows the "friendly
name" (identifier) of the element to be proxied to a Watir element
object that corresponds to the element type.
Defines an accessor method for an element that allows the " friendly name " ( identifier ) of the element to be proxied to a Watir element object that corresponds to the element type .
identifier
<not_specific>
signature
<not_specific>
element
<not_specific>
block
<not_specific>