Class: Capybara::Window

### Home Classes Methods

### In Files

- lib/capybara/window.rb

### Parent

Object

### Methods

- ::new
- #==
- #close
- #closed?
- #current?
- #eql?
- #exists?
- #hash
- #inspect
- #maximize
- #resize_to
- #size

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::Window

The Window class represents a browser window.

You can get an instance of the class by calling either of:

- {Capybara::Session#windows}

- {Capybara::Session#current_window}

- {Capybara::Session#window_opened_by}

- {Capybara::Session#switch_to_window}

Note that some drivers (e.g. Selenium) support getting size of/resizing/closing only

    current window. So if you invoke such method for:

    * window that is current, Capybara will make 2 Selenium method invocations
      (get handle of current window + get size/resize/close).
    * window that is not current, Capybara will make 4 Selenium method invocations
      (get handle of current window + switch to given handle + get size/resize/close + switch to original handle)

### Attributes

handle[R]

@return [String] a string that uniquely identifies window within session

session[R]

@return [Capybara::Session] session that this window belongs to

### Public Class Methods

new(session, handle) click to toggle source

@api private

    # File lib/capybara/window.rb, line 28
    def initialize(session, handle)
      @session = session
      @driver = session.driver
      @handle = handle
    end

### Public Instance Methods

==(other) click to toggle source
Alias for: eql?
close() click to toggle source

Close window.

If this method was called for window that is current, then after calling this method

    future invocations of other Capybara methods should raise
    `session.driver.no_such_window_error` until another window will be switched to.

@!macro about_current

    If this method was called for window that is not current, then after calling this method
    current window shouldn remain the same as it was before calling this method.

    # File lib/capybara/window.rb, line 65
    def close
      @driver.close_window(handle)
    end

closed?() click to toggle source

@return [Boolean] whether the window is closed

    # File lib/capybara/window.rb, line 42
    def closed?
      !exists?
    end

current?() click to toggle source

@return [Boolean] whether this window is the window in which commands are being executed

    # File lib/capybara/window.rb, line 48
    def current?
      @driver.current_window_handle == @handle
    rescue @driver.no_such_window_error
      false
    end

eql?(other) click to toggle source

    # File lib/capybara/window.rb, line 102
    def eql?(other)
      other.kind_of?(self.class) && @session == other.session && @handle == other.handle
    end

Also aliased as: ==
exists?() click to toggle source

@return [Boolean] whether the window is not closed

    # File lib/capybara/window.rb, line 36
    def exists?
      @driver.window_handles.include?(@handle)
    end

hash() click to toggle source

    # File lib/capybara/window.rb, line 107
    def hash
      @session.hash ^ @handle.hash
    end

inspect() click to toggle source

    # File lib/capybara/window.rb, line 111
    def inspect
      "#<Window @handle=#{@handle.inspect}>"
    end

maximize() click to toggle source

Maximize window.

If a particular driver (e.g. headless driver) doesn't have concept of maximizing it

    may not support this method.

@macro about_current

    # File lib/capybara/window.rb, line 98
    def maximize
      @driver.maximize_window(handle)
    end

resize_to(width, height) click to toggle source

Resize window.

@macro about_current @param width [String] the new window width in pixels @param height [String] the new window height in pixels

    # File lib/capybara/window.rb, line 86
    def resize_to(width, height)
      @driver.resize_window_to(handle, width, height)
    end

size() click to toggle source

Get window size.

@macro about_current @return [Array<(Fixnum, Fixnum)>] an array with width and height

    # File lib/capybara/window.rb, line 75
    def size
      @driver.window_size(handle)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.