Skip to content

Commit

Permalink
Replace clear method with values method
Browse files Browse the repository at this point in the history
The `values` method that will return an array of values for the radio buttons in the group.
  • Loading branch information
sivart84 committed Jan 13, 2014
1 parent d896581 commit fe66aca
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions lib/page-object/accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,46 +422,41 @@ def radio_button(name, identifier={:index => 0}, &block)
#
# 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 clear all radio buttons in the group, a method to
# return if a radio button in the group is selected (will return
# 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', 'clear_color', 'color_selected?',
# # 'color_elements', and 'color?' methods
# 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:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
# 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 || radio_elem.text == value
if radio_elem.value == value
return radio_elem.select
end
end
end
define_method("clear_#{name}") do
define_method("#{name}_values") do
result = []
platform.radio_buttons_for(identifier.clone).each do |radio_elem|
radio_elem.clear
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.text if radio_elem.selected?
return radio_elem.value if radio_elem.selected?
end
return false
end
Expand Down

0 comments on commit fe66aca

Please sign in to comment.