lib/capybara/node/actions.rb in capybara-2.0.3 vs lib/capybara/node/actions.rb in capybara-2.1.0.beta1

- old
+ new

@@ -7,34 +7,36 @@ # Finds a button or link by id, text or value and clicks it. Also looks at image # alt text inside the link. # # @param [String] locator Text, id or value of link or button # - def click_link_or_button(locator) - find(:link_or_button, locator).click + def click_link_or_button(locator, options={}) + find(:link_or_button, locator, options).click end alias_method :click_on, :click_link_or_button ## # # Finds a link by id or text and clicks it. Also looks at image # alt text inside the link. # # @param [String] locator Text, id or text of link + # @param options + # @option options [String] :href The value the href attribute must be # - def click_link(locator) - find(:link, locator).click + def click_link(locator, options={}) + find(:link, locator, options).click end ## # # Finds a button by id, text or value and clicks it. # # @param [String] locator Text, id or value of button # - def click_button(locator) - find(:button, locator).click + def click_button(locator, options={}) + find(:button, locator, options).click end ## # # Locate a text field or text area and fill it in with the given text @@ -45,11 +47,12 @@ # @param [String] locator Which field to fill in # @param [Hash{:with => String}] The value to fill in # def fill_in(locator, options={}) raise "Must pass a hash containing 'with'" if not options.is_a?(Hash) or not options.has_key?(:with) - find(:fillable_field, locator).set(options[:with]) + with = options.delete(:with) + find(:fillable_field, locator, options).set(with) end ## # # Find a radio button and mark it as checked. The radio button can be found @@ -57,12 +60,12 @@ # # page.choose('Male') # # @param [String] locator Which radio button to choose # - def choose(locator) - find(:radio_button, locator).set(true) + def choose(locator, options={}) + find(:radio_button, locator, options).set(true) end ## # # Find a check box and mark it as checked. The check box can be found @@ -70,12 +73,12 @@ # # page.check('German') # # @param [String] locator Which check box to check # - def check(locator) - find(:checkbox, locator).set(true) + def check(locator, options={}) + find(:checkbox, locator, options).set(true) end ## # # Find a check box and mark uncheck it. The check box can be found @@ -83,12 +86,12 @@ # # page.uncheck('German') # # @param [String] locator Which check box to uncheck # - def uncheck(locator) - find(:checkbox, locator).set(false) + def uncheck(locator, options={}) + find(:checkbox, locator, options).set(false) end ## # # Find a select box on the page and select a particular option from it. If the select @@ -100,13 +103,14 @@ # @param [String] value Which option to select # @param [Hash{:from => String}] The id, name or label of the select box # def select(value, options={}) if options.has_key?(:from) - find(:select, options[:from]).find(:option, value).select_option + from = options.delete(:from) + find(:select, from, options).find(:option, value, options).select_option else - find(:option, value).select_option + find(:option, value, options).select_option end end ## # @@ -119,13 +123,14 @@ # @param [String] value Which option to unselect # @param [Hash{:from => String}] The id, name or label of the select box # def unselect(value, options={}) if options.has_key?(:from) - find(:select, options[:from]).find(:option, value).unselect_option + from = options.delete(:from) + find(:select, from, options).find(:option, value, options).unselect_option else - find(:option, value).unselect_option + find(:option, value, options).unselect_option end end ## # @@ -135,14 +140,14 @@ # page.attach_file(locator, '/path/to/file.png') # # @param [String] locator Which field to attach the file to # @param [String] path The path of the file that will be attached, or an array of paths # - def attach_file(locator, path) + def attach_file(locator, path, options={}) Array(path).each do |p| raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s) end - find(:file_field, locator).set(path) + find(:file_field, locator, options).set(path) end end end end