Skip to content

Commit

Permalink
populate_page_with now supports radio groups
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Mar 5, 2014
1 parent b9bd99c commit d5fcffb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
=== Version 0.9.8
* Enhancements
* populate_page_with not supports radio groups

=== Version 0.9.7 / 2014-2-26
* Enhancements
* Table now supports exists?
Expand Down
8 changes: 4 additions & 4 deletions features/radio_button_group.feature
Expand Up @@ -16,12 +16,12 @@ Feature: Radio Button Groups
Scenario: Selecting grouped radio buttons by value
When I select the "ched" radio button in the group
Then the "ched" radio button should be selected in the group
Then the "emmen" radio button should not be selected
Then the "muen" radio button should not be selected
And the "emmen" radio button should not be selected
And the "muen" radio button should not be selected
When I select the "muen" radio button in the group
Then the "ched" radio button should not be selected
Then the "emmen" radio button should not be selected
Then the "muen" radio button should be selected in the group
And the "emmen" radio button should not be selected
And the "muen" radio button should be selected in the group

Scenario: Getting an array of elements for each radio button in the group
When I ask for the elements of a radio button group
Expand Down
10 changes: 10 additions & 0 deletions lib/page-object/page_populator.rb
Expand Up @@ -32,6 +32,7 @@ module PagePopulator
def populate_page_with(data)
data.each do |key, value|
populate_checkbox(key, value) if is_checkbox?(key) and is_enabled?(key)
populate_radiobuttongroup(key, value) if is_radiobuttongroup?(key)
populate_radiobutton(key, value) if is_radiobutton?(key) and is_enabled?(key)
populate_text(key, value) if is_text?(key) and is_enabled?(key)
end
Expand All @@ -53,6 +54,10 @@ def populate_radiobutton(key, value)
return self.send "clear_#{key}"
end

def populate_radiobuttongroup(key, value)
return self.send("select_#{key}", value)
end

def is_text?(key)
respond_to?("#{key}=".to_sym)
end
Expand All @@ -65,7 +70,12 @@ def is_radiobutton?(key)
respond_to?("select_#{key}".to_sym)
end

def is_radiobuttongroup?(key)
respond_to?("select_#{key}".to_sym) and respond_to?("#{key}_values")
end

def is_enabled?(key)
return false if is_radiobuttongroup?(key)
return true if (self.send "#{key}_element").tag_name == "textarea"
element = self.send("#{key}_element")
element.enabled? and element.visible?
Expand Down
6 changes: 6 additions & 0 deletions spec/page-object/page_populator_spec.rb
Expand Up @@ -9,6 +9,7 @@ class PageObjectTestPageObject
file_field(:ff, :id => 'id')
checkbox(:cb, :id => 'id')
radio_button(:rb, :id => 'id')
radio_button_group(:rbg, :id => 'id')
end

describe PageObject::PagePopulator do
Expand Down Expand Up @@ -86,6 +87,11 @@ class PageObjectTestPageObject
page_object.populate_page_with('rb' => false)
end

it "should select the correct element from a radio button group" do
page_object.should_receive(:select_rbg).with('blah')
page_object.populate_page_with('rbg' => 'blah')
end

it "should not populate a checkbox if it is disabled" do
page_object.should_not_receive(:check_cb)
page_object.should_receive(:cb_element).twice.and_return(browser)
Expand Down

0 comments on commit d5fcffb

Please sign in to comment.