Skip to content
Browse files

added text_area_elements to ElementLocator

  • Loading branch information...
1 parent 5d9e8a1 commit 388af4883596644784267862f13a34ebdf94b576 @cheezy cheezy committed Jan 9, 2012
View
1 ChangeLog
@@ -3,6 +3,7 @@
* Added #button_elements to ElementLocators
* Added #text_field_elements to ElementLocators
* Added #hidden_field_elements to ElementLocators
+ * Added #text_area_elements to ElementLocators
* Added #navigate_to to PageFactory to navigate to a page through previous pages
* Added #continue_navigation_to to PageFactory which begins at @current_page
* Added routes to PageFactory to collect routes through the site
View
3 features/html/multi_elements.html
@@ -16,5 +16,8 @@
<input class="hiddenfield" size="40" type="hidden" value="hidden 2"/>
<input class="hiddenfield" size="40" type="hidden" value="hidden 3"/>
+ <textarea rows="2" cols="20" class="textarea">textarea 1</textarea>
+ <textarea rows="2" cols="20" class="textarea">textarea 2</textarea>
+ <textarea rows="2" cols="20" class="textarea">textarea 3</textarea>
</body>
</html>
View
8 features/multi_elements.feature
@@ -24,4 +24,12 @@ Feature: Multi Elements
And the value of hidden field 2 should be "hidden 2"
And the value of hidden field 3 should be "hidden 3"
+ Scenario: Selecting text_areas
+ When I select the text area with class "textarea"
+ Then I should have 3 text areas
+ And the value of text area 1 should be "textarea 1"
+ And the value of text area 2 should be "textarea 2"
+ And the value of text area 3 should be "textarea 3"
+
+
View
12 features/step_definitions/multi_elements_steps.rb
@@ -43,3 +43,15 @@ class MultiElementsPage
Then /^the value of hidden field (\d+) should be "([^\"]*)"$/ do |hidden_field_num, value|
@elements[hidden_field_num.to_i - 1].value.should == value
end
+
+When /^I select the text area with class "([^\"]*)"$/ do |class_name|
+ @elements = @page.text_area_elements(:class => class_name)
+end
+
+Then /^I should have (\d+) text areas$/ do |num_text_areas|
+ @elements.size.should == num_text_areas.to_i
+end
+
+Then /^the value of text area (\d+) should be "([^\"]*)"$/ do |text_area_num, value|
+ @elements[text_area_num.to_i - 1].value.should == value
+end
View
17 lib/page-object/element_locators.rb
@@ -133,6 +133,23 @@ def text_area_element(identifier)
end
#
+ # Finds all text areas for the provided identifier
+ #
+ # @param [Hash] identifier how we find a text area. You can use a multiple paramaters
+ # by combining of any of the following except xpath. The valid keys are:
+ # * :class => Watir and Selenium
+ # * :css => Watir and Selenium
+ # * :id => Watir and Selenium
+ # * :index => Watir and Selenium
+ # * :name => Watir and Selenium
+ # * :tag_name => Watir and Selenium
+ # * :xpath => Watir and Selenium
+ #
+ def text_area_elements(identifier)
+ platform.text_areas_for(identifier.clone)
+ end
+
+ #
# Finds a select list
#
# @param [Hash] identifier how we find a select list. You can use a multiple paramaters
View
7 lib/page-object/platforms/selenium_webdriver/page_object.rb
@@ -254,6 +254,13 @@ def text_area_for(identifier)
end
#
+ # platform method to retrieve all text area elements
+ #
+ def text_areas_for(identifier)
+ find_selenium_elements(identifier, Elements::TextArea, 'textarea')
+ end
+
+ #
# platform method to get the currently selected value from a select list
# See PageObject::Accessors#select_list
#
View
7 lib/page-object/platforms/watir_webdriver/page_object.rb
@@ -245,6 +245,13 @@ def text_area_for(identifier)
end
#
+ # platform method to retrieve an array of textarea elements
+ #
+ def text_areas_for(identifier)
+ find_watir_elements("textareas(identifier)", Elements::TextArea, identifier)
+ end
+
+ #
# platform method to get the currently selected value from a select list
# See PageObject::Accessors#select_list
#
View
12 spec/page-object/element_locators_spec.rb
@@ -52,6 +52,12 @@ class ElementLocatorsTestPageObject
element = watir_page_object.text_area_element(:id => 'blah')
element.should be_instance_of PageObject::Elements::TextArea
end
+
+ it "should find all text area elements" do
+ watir_browser.should_receive(:textareas).with(:id => 'blah').and_return([watir_browser])
+ elements = watir_page_object.text_area_elements(:id => 'blah')
+ elements[0].should be_instance_of PageObject::Elements::TextArea
+ end
it "should find a select list element" do
watir_browser.should_receive(:select_list).with(:id => 'blah').and_return(watir_browser)
@@ -226,6 +232,12 @@ class ElementLocatorsTestPageObject
element = selenium_page_object.text_area_element(:id => 'blah')
element.should be_instance_of PageObject::Elements::TextArea
end
+
+ it "should find all text area elements" do
+ selenium_browser.should_receive(:find_elements).with(:id, 'blah').and_return([selenium_browser])
+ elements = selenium_page_object.text_area_elements(:id => 'blah')
+ elements[0].should be_instance_of PageObject::Elements::TextArea
+ end
it "should find a select list element" do
selenium_browser.should_receive(:find_element).with(:id, 'blah').and_return(selenium_browser)

0 comments on commit 388af48

Please sign in to comment.
Something went wrong with that request. Please try again.