lib/page-object/accessors.rb in page_object-1.1.1 vs lib/page-object/accessors.rb in page_object-1.1.2

- old
+ new

@@ -205,11 +205,11 @@ # * :title => Watir and Selenium # * :value => Watir only # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # - def text_field(name, identifier={:index => 0}, &block) + def text_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_field_for', &block) define_method(name) do return platform.text_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end @@ -400,11 +400,11 @@ self.send("#{name}_element").checked? end end # - # adds four methods - one to select, another to return if a radio button + # adds four methods - one to select, another to return if a radio button # is selected, another method to return a PageObject::Elements::RadioButton # object representing the radio button element, and another to check # the radio button's existence. # # @example @@ -1217,11 +1217,24 @@ # * :index => Watir and Selenium # * :name => Watir and Selenium # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # - def element(name, tag, identifier={:index => 0}, &block) + def element(name, tag=:element, identifier={ :index => 0 }, &block) + # default tag to :element + # + # element 'button', css: 'some css' + # + # is the same as + # + # element 'button', :element, css: 'some css' + # + if tag.is_a?(Hash) + identifier = tag + tag = :element + end + define_method("#{name}") do self.send("#{name}_element").text end define_method("#{name}_element") do return call_block(&block) if block_given? @@ -1250,10 +1263,23 @@ # * :index => Watir and Selenium # * :name => Watir and Selenium # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # - def elements(name, tag, identifier={:index => 0}, &block) + def elements(name, tag=:element, identifier={:index => 0}, &block) + # default tag to :element + # + # elements 'button', css: 'some css' + # + # is the same as + # + # elements 'button', :element, css: 'some css' + # + if tag.is_a?(Hash) + identifier = tag + tag = :element + end + define_method("#{name}_elements") do return call_block(&block) if block_given? platform.elements_for(tag, identifier.clone) end end