lib/page-object/accessors.rb in page-object-0.9.4 vs lib/page-object/accessors.rb in page-object-0.9.5

- old
+ new

@@ -418,10 +418,60 @@ standard_methods(name, identifier, 'radio_button_for', &block) end alias_method :radio, :radio_button # + # adds five methods to help interact with a radio button group - + # a method to select a radio button in the group by given value/text, + # a method to return the values of all radio buttins in the group, a method + # to return if a radio button in the group is selected (will return + # the text of the selected radio button, if true), a method to return + # an array of PageObject::Elements::RadioButton objects representing + # the radio button group, and finally a method to check the existence + # of the radio button group. + # + # @example + # radio_button_group(:color, :name => "preferred_color") + # will generate 'select_color', 'color_values', 'color_selected?', + # 'color_elements', and 'color?' methods + # + # @param [Symbol] the name used for the generated methods + # @param [Hash] shared identifier for the radio button group. Typically, a 'name' attribute. + # The valid keys are: + # * :name => Watir and Selenium + # + def radio_button_group(name, identifier) + define_method("select_#{name}") do |value| + platform.radio_buttons_for(identifier.clone).each do |radio_elem| + if radio_elem.value == value + return radio_elem.select + end + end + end + define_method("#{name}_values") do + result = [] + platform.radio_buttons_for(identifier.clone).each do |radio_elem| + result << radio_elem.value + end + return result + end + define_method("#{name}_selected?") do + platform.radio_buttons_for(identifier.clone).each do |radio_elem| + return radio_elem.value if radio_elem.selected? + end + return false + end + define_method("#{name}_elements") do + return platform.radio_buttons_for(identifier.clone) + end + define_method("#{name}?") do + return platform.radio_buttons_for(identifier.clone).any? + end + end + alias_method :radio_group, :radio_button_group + + # # adds three methods - one to click a button, another to # return the button element, and another to check the button's existence. # # @example # button(:purchase, :id => 'purchase') @@ -1153,14 +1203,18 @@ # * :index => Watir and Selenium # * :name => Watir and Selenium # * :xpath => Watir and Selenium # @param optional block to be invoked when element method is called # - LocatorGenerator::BASIC_ELEMENTS.each do |type| - define_method(type) do |name, *identifier, &block| + LocatorGenerator::BASIC_ELEMENTS.each do |tag| + define_method(tag) do |name, *identifier, &block| identifier = identifier[0] ? identifier[0] : {:index => 0} - element(name, type, identifier, &block) + element(name, tag, identifier, &block) end + define_method("#{tag}s") do |name, *identifier, &block| + identifier = identifier[0] ? identifier[0] : {:index => 0} + elements(name, tag, identifier, &block) + end unless tag == :param end def standard_methods(name, identifier, method, &block) define_method("#{name}_element") do return call_block(&block) if block_given?