Sha256: d7e178d743d31c7f594c0fe31262b741e60ec5054e3ad368f372457b6e76fabe

Contents?: true

Size: 1.03 KB

Versions: 30

Compression:

Stored size: 1.03 KB

Contents

module Watir
  module HasWindow

    #
    # Returns browser windows array.
    #
    # @example
    #   browser.windows(title: 'closeable window')
    #
    # @return [Array<Window>]
    #

    def windows(*args)
      all = @driver.window_handles.map { |handle| Window.new(@driver, handle: handle) }

      if args.empty?
        all
      else
        filter_windows extract_selector(args), all
      end
    end

    #
    # Returns browser window.
    #
    # @example
    #   browser.window(title: 'closeable window')
    #
    # @return [Window]
    #

    def window(*args, &blk)
      win = Window.new @driver, extract_selector(args)

      win.use(&blk) if block_given?

      win
    end

    private

    def filter_windows(selector, windows)
      unless selector.keys.all? { |k| [:title, :url].include? k }
        raise ArgumentError, "invalid window selector: #{selector.inspect}"
      end

      windows.select do |win|
        selector.all? { |key, value| value === win.send(key) }
      end
    end

  end # HasWindow
end # Watir

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
watir-6.6.3 lib/watir/has_window.rb
watir-6.6.2 lib/watir/has_window.rb
watir-6.6.1 lib/watir/has_window.rb
watir-6.6.0 lib/watir/has_window.rb
watir-6.5.0 lib/watir/has_window.rb
watir-6.4.3 lib/watir/has_window.rb
watir-6.4.2 lib/watir/has_window.rb
watir-6.4.1 lib/watir/has_window.rb
watir-6.4.0 lib/watir/has_window.rb
watir-6.4.0.rc2 lib/watir/has_window.rb
watir-6.4.0.rc1 lib/watir/has_window.rb
watir-6.3.0 lib/watir/has_window.rb
watir-6.2.1 lib/watir/has_window.rb
watir-6.2.0 lib/watir/has_window.rb
watir-6.1.0 lib/watir/has_window.rb
watir-6.0.3 lib/watir/has_window.rb
watir-6.0.2 lib/watir/has_window.rb
watir-6.0.1 lib/watir/has_window.rb
watir-webdriver-0.9.9 lib/watir-webdriver/has_window.rb
watir-6.0.0 lib/watir/has_window.rb