Sha256: 23613315e09a4d473583334dc284bd4e855937f6afc262b5b8b02331731df960

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

module Capybara
  module Searchable
    def find(*args)
      all(*args).first
    end

    def find_field(locator)
      find(:xpath, XPath.field(locator))
    end
    alias_method :field_labeled, :find_field

    def find_link(locator)
      find(:xpath, XPath.link(locator))
    end

    def find_button(locator)
      find(:xpath, XPath.button(locator))
    end

    def find_by_id(id)
      find(:css, "##{id}")
    end

    def all(*args)
      options = if args.last.is_a?(Hash) then args.pop else {} end
      if args[1].nil?
        kind, locator = Capybara.default_selector, args.first
      else
        kind, locator = args
      end
      locator = XPath.from_css(locator) if kind == :css

      results = all_unfiltered(locator)

      if options[:text]
        results = results.select { |n| n.text.match(options[:text]) }
      end

      if options[:visible] or Capybara.ignore_hidden_elements
        results = results.select { |n| n.visible? }
      end

      results
    end

    private

    def all_unfiltered(locator)
      raise "Must be overridden"
    end

  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
capybara-0.3.7 lib/capybara/searchable.rb
capybara-0.3.6 lib/capybara/searchable.rb
h13ronim-capybara-0.3.0.1 lib/capybara/searchable.rb
capybara-0.3.5 lib/capybara/searchable.rb
bjeanes-capybara-0.3.2 lib/capybara/searchable.rb
bjeanes-capybara-0.3.1 lib/capybara/searchable.rb