Class: Capybara::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/window.rb

Overview

The Window class represents a browser window.

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

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)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, handle) ⇒ Window

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Window.



28
29
30
31
32
# File 'lib/capybara/window.rb', line 28

def initialize(session, handle)
  @session = session
  @driver = session.driver
  @handle = handle
end

Instance Attribute Details

#handleString (readonly)



22
23
24
# File 'lib/capybara/window.rb', line 22

def handle
  @handle
end

#sessionCapybara::Session (readonly)



25
26
27
# File 'lib/capybara/window.rb', line 25

def session
  @session
end

Instance Method Details

#closeObject

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.

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.



65
66
67
# File 'lib/capybara/window.rb', line 65

def close
  @driver.close_window(handle)
end

#closed?Boolean



42
43
44
# File 'lib/capybara/window.rb', line 42

def closed?
  !exists?
end

#current?Boolean



48
49
50
51
52
# File 'lib/capybara/window.rb', line 48

def current?
  @driver.current_window_handle == @handle
rescue @driver.no_such_window_error
  false
end

#eql?(other) ⇒ Boolean Also known as: ==



102
103
104
# File 'lib/capybara/window.rb', line 102

def eql?(other)
  other.kind_of?(self.class) && @session == other.session && @handle == other.handle
end

#exists?Boolean



36
37
38
# File 'lib/capybara/window.rb', line 36

def exists?
  @driver.window_handles.include?(@handle)
end

#hashObject



107
108
109
# File 'lib/capybara/window.rb', line 107

def hash
  @session.hash ^ @handle.hash
end

#inspectObject



111
112
113
# File 'lib/capybara/window.rb', line 111

def inspect
  "#<Window @handle=#{@handle.inspect}>"
end

#maximizeObject

Maximize window.

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

may not support this method.

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.



98
99
100
# File 'lib/capybara/window.rb', line 98

def maximize
  @driver.maximize_window(handle)
end

#resize_to(width, height) ⇒ Object

Resize window.

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.



86
87
88
# File 'lib/capybara/window.rb', line 86

def resize_to(width, height)
  @driver.resize_window_to(handle, width, height)
end

#sizeArray<(Fixnum, Fixnum)>

Get window size.

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.



75
76
77
# File 'lib/capybara/window.rb', line 75

def size
  @driver.window_size(handle)
end