Sha256: cff496138ff0670f91a735103c4dcb443b7ace0f90a60ca76d09cdf6c3b7f516

Contents?: true

Size: 1.65 KB

Versions: 49

Compression:

Stored size: 1.65 KB

Contents

require "webrat/core_extensions/detect_mapped"
require "webrat/core/locators/locator"

module Webrat
  module Locators

    class SelectOptionLocator < Locator # :nodoc:

      def initialize(session, dom, option_text, id_or_name_or_label)
        @session = session
        @dom = dom
        @option_text = option_text
        @id_or_name_or_label = id_or_name_or_label
      end

      def locate
        if @id_or_name_or_label
          field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!

          field.options.detect do |o|
            if @option_text.is_a?(Regexp)
              Webrat::XML.inner_html(o.element) =~ @option_text
            else
              Webrat::XML.inner_html(o.element) == @option_text.to_s
            end
          end
        else
          option_element = option_elements.detect do |o|
            if @option_text.is_a?(Regexp)
              Webrat::XML.inner_html(o) =~ @option_text
            else
              Webrat::XML.inner_html(o) == @option_text.to_s
            end
          end

          SelectOption.load(@session, option_element)
        end
      end

      def option_elements
        Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
      end

      def error_message
        if @id_or_name_or_label
          "The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
        else
          "Could not find option #{@option_text.inspect}"
        end
      end

    end

    def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
      SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
    end

  end
end

Version data entries

49 entries across 49 versions & 21 rubygems

Version Path
aslakhellesoy-webrat-0.4.4.1 lib/webrat/core/locators/select_option_locator.rb
casebook-webrat-0.4.4.1 lib/webrat/core/locators/select_option_locator.rb
cavalle-webrat-0.4.4.1 lib/webrat/core/locators/select_option_locator.rb
cavalle-webrat-0.4.4.2 lib/webrat/core/locators/select_option_locator.rb
davidtrogers-webrat-0.4.4.2 lib/webrat/core/locators/select_option_locator.rb
dbrady-webrat-0.4.4.1 lib/webrat/core/locators/select_option_locator.rb
dbrady-webrat-0.4.4.2 lib/webrat/core/locators/select_option_locator.rb
dbrady-webrat-0.4.4 lib/webrat/core/locators/select_option_locator.rb
diabolo-diabolo-webrat-0.4.4 lib/webrat/core/locators/select_option_locator.rb
diabolo-webrat-0.4.3 lib/webrat/core/locators/select_option_locator.rb
diabolo-webrat-0.4.4.1 lib/webrat/core/locators/select_option_locator.rb
diabolo-webrat-0.4.4.2 lib/webrat/core/locators/select_option_locator.rb
diabolo-webrat-0.4.4 lib/webrat/core/locators/select_option_locator.rb
dstrelau-webrat-0.5.1 lib/webrat/core/locators/select_option_locator.rb
emipair-webrat-0.0.1 lib/webrat/core/locators/select_option_locator.rb
futuresinc-webrat-0.4.4.100 lib/webrat/core/locators/select_option_locator.rb
futuresinc-webrat-0.4.4.99 lib/webrat/core/locators/select_option_locator.rb
garnierjm-webrat-0.4.5 lib/webrat/core/locators/select_option_locator.rb
hardbap-webrat-0.5.1 lib/webrat/core/locators/select_option_locator.rb
hardbap-webrat-0.5.2 lib/webrat/core/locators/select_option_locator.rb