lib/page-object/accessors.rb in page-object-1.0.2 vs lib/page-object/accessors.rb in page-object-1.0.3

- old
+ new

@@ -11,11 +11,11 @@ # @see PageObject::SeleniumPageObject for the selenium implementation of the platform delegate # module Accessors # - # Set some values that can be used withing the class. This is + # Set some values that can be used within the class. This is # typically used to provide values that help build dynamic urls in # the page_url method # # @param [Hash] the value to set the params # @@ -64,24 +64,22 @@ # expected_title "Google" # page.has_expected_title? # def wait_for_expected_title(expected_title, timeout=::PageObject.default_element_wait) define_method("wait_for_expected_title?") do - page_title = title - has_expected_title = (expected_title === page_title) - if not has_expected_title and not timeout.nil? - wait_until(timeout, "Expected title '#{expected_title}' instead of '#{page_title}'") do - has_expected_title = (expected_title === page_title) - has_expected_title - end - end - raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title + error_message = lambda { "Expected title '#{expected_title}' instead of '#{title}'" } + + has_expected_title = (expected_title === title) + wait_until(timeout, error_message.call) do + has_expected_title = (expected_title === title) + end unless has_expected_title + + raise error_message.call unless has_expected_title has_expected_title end end - # # Creates a method that compares the expected_title of a page against the actual. # @param [String] expected_title the literal expected title for the page # @param [Regexp] expected_title the expected title pattern for the page # @return [boolean] @@ -193,11 +191,11 @@ # text_field(:first_name, :id => "first_name") # # will generate 'first_name', 'first_name=', 'first_name_element', # # 'first_name?' methods # # @param [String] the name used for the generated methods - # @param [Hash] identifier how we find a text field. You can use a multiple paramaters + # @param [Hash] identifier how we find a text field. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -229,11 +227,11 @@ # @example # hidden_field(:user_id, :id => "user_identity") # # will generate 'user_id', 'user_id_element' and 'user_id?' methods # # @param [String] the name used for the generated methods - # @param [Hash] identifier how we find a hidden field. You can use a multiple paramaters + # @param [Hash] identifier how we find a hidden field. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -261,11 +259,11 @@ # text_area(:address, :id => "address") # # will generate 'address', 'address=', 'address_element', # # 'address?' methods # # @param [String] the name used for the generated methods - # @param [Hash] identifier how we find a text area. You can use a multiple paramaters + # @param [Hash] identifier how we find a text area. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -297,11 +295,11 @@ # @example # select_list(:state, :id => "state") # # will generate 'state', 'state=', 'state_element', 'state?', "state_options" methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a select list. You can use a multiple paramaters + # @param [Hash] identifier how we find a select list. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -337,11 +335,11 @@ # @example # link(:add_to_cart, :text => "Add to Cart") # # will generate 'add_to_cart', 'add_to_cart_element', and 'add_to_cart?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a link. You can use a multiple paramaters + # @param [Hash] identifier how we find a link. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Watir and Selenium # * :href => Watir and Selenium # * :id => Watir and Selenium @@ -373,11 +371,11 @@ # checkbox(:active, :name => "is_active") # # will generate 'check_active', 'uncheck_active', 'active_checked?', # # 'active_element', and 'active?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a checkbox. You can use a multiple paramaters + # @param [Hash] identifier how we find a checkbox. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -402,23 +400,22 @@ self.send("#{name}_element").checked? end end # - # adds five methods - one to select, another to clear, - # another to return if a radio button is selected, - # another method to return a PageObject::Elements::RadioButton + # adds four methods - one to select, another to return if a radio button + # is selected, another method to return a PageObject::Elements::RadioButton # object representing the radio button element, and another to check # the radio button's existence. # # @example # radio_button(:north, :id => "north") - # # will generate 'select_north', 'clear_north', 'north_selected?', + # # will generate 'select_north', 'north_selected?', # # 'north_element', and 'north?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a radio button. You can use a multiple paramaters + # @param [Hash] identifier how we find a radio button. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -432,25 +429,21 @@ standard_methods(name, identifier, 'radio_button_for', &block) define_method("select_#{name}") do return platform.select_radio(identifier.clone) unless block_given? self.send("#{name}_element").select end - define_method("clear_#{name}") do - return platform.clear_radio(identifier.clone) unless block_given? - self.send("#{name}_element").clear - end define_method("#{name}_selected?") do return platform.radio_selected?(identifier.clone) unless block_given? self.send("#{name}_element").selected? end 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 + # a method to return the values of all radio buttons 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. @@ -502,11 +495,11 @@ # @example # button(:purchase, :id => 'purchase') # # will generate 'purchase', 'purchase_element', and 'purchase?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a button. You can use a multiple paramaters + # @param [Hash] identifier how we find a button. You can use a multiple parameters # 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 @@ -533,11 +526,11 @@ # @example # div(:message, :id => 'message') # # will generate 'message', 'message_element', and 'message?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a div. You can use a multiple paramaters + # @param [Hash] identifier how we find a div. You can use a multiple parameters # 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 @@ -562,11 +555,11 @@ # @example # span(:alert, :id => 'alert') # # will generate 'alert', 'alert_element', and 'alert?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a span. You can use a multiple paramaters + # @param [Hash] identifier how we find a span. You can use a multiple parameters # 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 @@ -593,11 +586,11 @@ # @example # table(:cart, :id => 'shopping_cart') # # will generate a 'cart', 'cart_element' and 'cart?' method # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a table. You can use a multiple paramaters + # @param [Hash] identifier how we find a table. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -621,11 +614,11 @@ # @example # cell(:total, :id => 'total_cell') # # will generate 'total', 'total_element', and 'total?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a cell. You can use a multiple paramaters + # @param [Hash] identifier how we find a cell. You can use a multiple parameters # 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 @@ -651,11 +644,11 @@ # @example # image(:logo, :id => 'logo') # # will generate 'logo_element' and 'logo?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find an image. You can use a multiple paramaters + # @param [Hash] identifier how we find an image. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :alt => Watir and Selenium # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium @@ -677,11 +670,11 @@ # @example # form(:login, :id => 'login') # # will generate 'login_element' and 'login?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a form. You can use a multiple paramaters + # @param [Hash] identifier how we find a form. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :action => Watir and Selenium # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium @@ -701,11 +694,11 @@ # @example # list_item(:item_one, :id => 'one') # # will generate 'item_one', 'item_one_element', and 'item_one?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a list item. You can use a multiple paramaters + # @param [Hash] identifier how we find a list item. You can use a multiple parameters # 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 @@ -722,20 +715,20 @@ end end alias_method :li, :list_item # - # adds three methods - one to return the text within the unorderd + # adds three methods - one to return the text within the unordered # list, one to retrieve the unordered list element, and another to # check it's existence. # # @example # unordered_list(:menu, :id => 'main_menu') # # will generate 'menu', 'menu_element' and 'menu?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find an unordered list. You can use a multiple paramaters + # @param [Hash] identifier how we find an unordered list. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -751,20 +744,20 @@ end end alias_method :ul, :unordered_list # - # adds three methods - one to return the text withing the ordered + # adds three methods - one to return the text within the ordered # list, one to retrieve the ordered list element, and another to # test it's existence. # # @example # ordered_list(:top_five, :id => 'top') # # will generate 'top_five', 'top_five_element' and 'top_five?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find an ordered list. You can use a multiple paramaters + # @param [Hash] identifier how we find an ordered list. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -788,11 +781,11 @@ # @example # h1(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H1. You can use a multiple paramaters + # @param [Hash] identifier how we find a H1. You can use a multiple parameters # 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 @@ -815,11 +808,11 @@ # @example # h2(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H2. You can use a multiple paramaters + # @param [Hash] identifier how we find a H2. You can use a multiple parameters # 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 @@ -842,11 +835,11 @@ # @example # h3(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H3. You can use a multiple paramaters + # @param [Hash] identifier how we find a H3. You can use a multiple parameters # 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 @@ -869,11 +862,11 @@ # @example # h4(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H4. You can use a multiple paramaters + # @param [Hash] identifier how we find a H4. You can use a multiple parameters # 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 @@ -896,11 +889,11 @@ # @example # h5(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H5. You can use a multiple paramaters + # @param [Hash] identifier how we find a H5. You can use a multiple parameters # 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 @@ -923,11 +916,11 @@ # @example # h6(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a H6. You can use a multiple paramaters + # @param [Hash] identifier how we find a H6. You can use a multiple parameters # 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 @@ -950,11 +943,11 @@ # @example # paragraph(:title, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a paragraph. You can use a multiple paramaters + # @param [Hash] identifier how we find a paragraph. You can use a multiple parameters # 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 @@ -978,11 +971,11 @@ # @example # file_field(:the_file, :id => 'file_to_upload') # # will generate 'the_file=', 'the_file_element', and 'the_file?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a file_field. You can use a multiple paramaters + # @param [Hash] identifier how we find a file_field. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -1007,11 +1000,11 @@ # @example # label(:message, :id => 'message') # # will generate 'message', 'message_element', and 'message?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a label. You can use a multiple paramaters + # @param [Hash] identifier how we find a label. You can use a multiple parameters # 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 @@ -1035,11 +1028,11 @@ # @example # area(:message, :id => 'message') # # will generate 'message', 'message_element', and 'message?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find an area. You can use a multiple paramaters + # @param [Hash] identifier how we find an area. You can use a multiple parameters # 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 @@ -1063,11 +1056,11 @@ # @example # canvas(:my_canvas, :id => 'canvas_id') # # will generate 'my_canvas_element' and 'my_canvas?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a canvas. You can use a multiple paramaters + # @param [Hash] identifier how we find a canvas. You can use a multiple parameters # 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 @@ -1086,11 +1079,11 @@ # @example # audio(:acdc, :id => 'audio_id') # # will generate 'acdc_element' and 'acdc?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find an audio element. You can use a multiple paramaters + # @param [Hash] identifier how we find an audio element. You can use a multiple parameters # 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 @@ -1109,11 +1102,11 @@ # @example # video(:movie, :id => 'video_id') # # will generate 'movie_element' and 'movie?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a video element. You can use a multiple paramaters + # @param [Hash] identifier how we find a video element. You can use a multiple parameters # 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 @@ -1124,19 +1117,46 @@ def video(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'video_for', &block) end # + # adds three methods - one to retrieve the text of a b element, another to + # retrieve a b element, and another to check for it's existence. + # + # @example + # b(:bold, :id => 'title') + # # will generate 'bold', 'bold_element', and 'bold?' methods + # + # @param [Symbol] the name used for the generated methods + # @param [Hash] identifier how we find a b. You can use a multiple parameters + # 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 + # * :xpath => Watir and Selenium + # @param optional block to be invoked when element method is called + # + def b(name, identifier={:index => 0}, &block) + standard_methods(name, identifier,'b_for', &block) + define_method(name) do + return platform.b_text_for identifier.clone unless block_given? + self.send("#{name}_element").text + end + end + + # # adds two methods - one to retrieve a svg, and another to check # the svg's existence. # # @example # svg(:circle, :id => 'circle') # # will generate 'circle_element', and 'circle?' methods # # @param [Symbol] the name used for the generated methods - # @param [Hash] identifier how we find a svg. You can use a multiple paramaters + # @param [Hash] identifier how we find a svg. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -1157,11 +1177,11 @@ # element(:title, :header, :id => 'title') # # will generate 'title', 'title_element', and 'title?' methods # # @param [Symbol] the name used for the generated methods # @param [Symbol] the name of the tag for the element - # @param [Hash] identifier how we find an element. You can use a multiple paramaters + # @param [Hash] identifier how we find an element. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -1190,11 +1210,11 @@ # elements(:title, :header, :id => 'title') # # will generate ''title_elements' # # @param [Symbol] the name used for the generated methods # @param [Symbol] the name of the tag for the element - # @param [Hash] identifier how we find an element. You can use a multiple paramaters + # @param [Hash] identifier how we find an element. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -1219,11 +1239,11 @@ # articles(:my_article, :id => 'article_id') # will generate 'my_article_elements' # # @param [Symbol] the name used for the generated methods # @param [Symbol] the name of the tag for the element - # @param [Hash] identifier how we find an element. You can use a multiple paramaters + # @param [Hash] identifier how we find an element. You can use a multiple parameters # by combining of any of the following except xpath. The valid keys are: # * :class => Watir and Selenium # * :css => Selenium only # * :id => Watir and Selenium # * :index => Watir and Selenium @@ -1284,17 +1304,17 @@ end # # methods to fetch multiple elements of the same type # - # adds a method to the page object to retrun all of the matching elements + # adds a method to the page object to return all of the matching elements # # @example # text_fields(:first_name, :id => "first_name") # # will generate 'first_name_elements' # # @param [String] the name used for the generated methods - # @param [Hash] identifier how we find a text field. You can use a multiple paramaters + # @param [Hash] identifier how we find a text field. You can use a multiple parameters # by combining of any of the following except xpath. The valid # keys are the same ones supported by the standard methods. # @param optional block to be invoked when element method is called # idx = LocatorGenerator::ADVANCED_ELEMENTS.find_index { |type| type == :checkbox }