lib/page-object/accessors.rb in page-object-0.2.3 vs lib/page-object/accessors.rb in page-object-0.2.4

- old
+ new

@@ -67,14 +67,16 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def text_field(name, identifier=nil, &block) define_method(name) do - platform.text_field_value_for identifier.clone + return platform.text_field_value_for identifier.clone unless block + self.send("#{name}_element").value end define_method("#{name}=") do |value| - platform.text_field_value_set(identifier.clone, value) + return platform.text_field_value_set(identifier.clone, value) unless block + self.send("#{name}_element").value = value end define_method("#{name}_element") do return call_block(&block) if block platform.text_field_for(identifier.clone) end @@ -102,11 +104,12 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def hidden_field(name, identifier=nil, &block) define_method(name) do - platform.hidden_field_value_for identifier.clone + return platform.hidden_field_value_for identifier.clone unless block + self.send("#{name}_element").value end define_method("#{name}_element") do return call_block(&block) if block platform.hidden_field_for(identifier.clone) end @@ -134,14 +137,16 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def text_area(name, identifier=nil, &block) define_method(name) do - platform.text_area_value_for identifier.clone + return platform.text_area_value_for identifier.clone unless block + self.send("#{name}_element").value end define_method("#{name}=") do |value| - platform.text_area_value_set(identifier.clone, value) + return platform.text_area_value_set(identifier.clone, value) unless block + self.send("#{name}_element").value = value end define_method("#{name}_element") do return call_block(&block) if block platform.text_area_for(identifier.clone) end @@ -169,14 +174,16 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def select_list(name, identifier=nil, &block) define_method(name) do - platform.select_list_value_for identifier.clone + return platform.select_list_value_for identifier.clone unless block + self.send("#{name}_element").value end define_method("#{name}=") do |value| - platform.select_list_value_set(identifier.clone, value) + return platform.select_list_value_set(identifier.clone, value) unless block + self.send("#{name}_element").select(value) end define_method("#{name}_element") do return call_block(&block) if block platform.select_list_for(identifier.clone) end @@ -206,11 +213,12 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def link(name, identifier=nil, &block) define_method(name) do - platform.click_link_for identifier.clone + return platform.click_link_for identifier.clone unless block + self.send("#{name}_element").click end define_method("#{name}_element") do return call_block(&block) if block platform.link_for(identifier.clone) end @@ -236,17 +244,20 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def checkbox(name, identifier=nil, &block) define_method("check_#{name}") do - platform.check_checkbox(identifier.clone) + return platform.check_checkbox(identifier.clone) unless block + self.send("#{name}_element").check end define_method("uncheck_#{name}") do - platform.uncheck_checkbox(identifier.clone) + return platform.uncheck_checkbox(identifier.clone) unless block + self.send("#{name}_element").uncheck end define_method("#{name}_checked?") do - platform.checkbox_checked?(identifier.clone) + return platform.checkbox_checked?(identifier.clone) unless block + self.send("#{name}_element").checked? end define_method("#{name}_element") do return call_block(&block) if block platform.checkbox_for(identifier.clone) end @@ -273,17 +284,20 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def radio_button(name, identifier=nil, &block) define_method("select_#{name}") do - platform.select_radio(identifier.clone) + return platform.select_radio(identifier.clone) unless block + self.send("#{name}_element").select end define_method("clear_#{name}") do - platform.clear_radio(identifier.clone) + return platform.clear_radio(identifier.clone) unless block + self.send("#{name}_element").clear end define_method("#{name}_selected?") do - platform.radio_selected?(identifier.clone) + return platform.radio_selected?(identifier.clone) unless block + self.send("#{name}_element").selected? end define_method("#{name}_element") do return call_block(&block) if block platform.radio_button_for(identifier.clone) end @@ -304,16 +318,18 @@ # * :class => Watir and Selenium # * :id => Watir and Selenium # * :index => Watir and Selenium # * :name => Watir and Selenium # * :text => Watir only + # * :value => Watir and Selenium # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def button(name, identifier=nil, &block) define_method(name) do - platform.click_button_for identifier.clone + return platform.click_button_for identifier.clone unless block + self.send("#{name}_element").click end define_method("#{name}_element") do return call_block(&block) if block platform.button_for(identifier.clone) end @@ -339,11 +355,12 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def div(name, identifier=nil, &block) define_method(name) do - platform.div_text_for identifier.clone + return platform.div_text_for identifier.clone unless block + self.send("#{name}_element").text end define_method("#{name}_element") do return call_block(&block) if block platform.div_for(identifier.clone) end @@ -368,11 +385,12 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def span(name, identifier=nil, &block) define_method(name) do - platform.span_text_for identifier.clone + return platform.span_text_for identifier.clone unless block + self.send("#{name}_element").text end define_method("#{name}_element") do return call_block(&block) if block platform.span_for(identifier.clone) end @@ -423,11 +441,12 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def cell(name, identifier=nil, &block) define_method("#{name}") do - platform.cell_text_for identifier.clone + return platform.cell_text_for identifier.clone unless block + self.send("#{name}_element").text end define_method("#{name}_element") do return call_block(&block) if block platform.cell_for(identifier.clone) end @@ -501,10 +520,11 @@ # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # def list_item(name, identifier=nil, &block) define_method(name) do - platform.list_item_text_for identifier.clone + return platform.list_item_text_for identifier.clone unless block + self.send("#{name}_element").text end define_method("#{name}_element") do return call_block(&block) if block platform.list_item_for(identifier.clone) end