Class: Capybara::Window
- Inherits:
-
Object
- Object
- Capybara::Window
- 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
-
#handle ⇒ String
readonly
A string that uniquely identifies window within session.
-
#session ⇒ Capybara::Session
readonly
Session that this window belongs to.
Instance Method Summary collapse
-
#close ⇒ Object
Close window.
-
#closed? ⇒ Boolean
Whether the window is closed.
-
#current? ⇒ Boolean
Whether this window is the window in which commands are being executed.
- #eql?(other) ⇒ Boolean (also: #==)
-
#exists? ⇒ Boolean
Whether the window is not closed.
- #hash ⇒ Object
-
#initialize(session, handle) ⇒ Window
constructor
private
A new instance of Window.
- #inspect ⇒ Object
-
#maximize ⇒ Object
Maximize window.
-
#resize_to(width, height) ⇒ Object
Resize window.
-
#size ⇒ Array<(Fixnum, Fixnum)>
Get window size.
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.
29 30 31 32 33 |
# File 'lib/capybara/window.rb', line 29 def initialize(session, handle) @session = session @driver = session.driver @handle = handle end |
Instance Attribute Details
#handle ⇒ String (readonly)
Returns a string that uniquely identifies window within session.
23 24 25 |
# File 'lib/capybara/window.rb', line 23 def handle @handle end |
#session ⇒ Capybara::Session (readonly)
Returns session that this window belongs to.
26 27 28 |
# File 'lib/capybara/window.rb', line 26 def session @session end |
Instance Method Details
#close ⇒ Object
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.
66 67 68 |
# File 'lib/capybara/window.rb', line 66 def close @driver.close_window(handle) end |
#closed? ⇒ Boolean
Returns whether the window is closed.
43 44 45 |
# File 'lib/capybara/window.rb', line 43 def closed? !exists? end |
#current? ⇒ Boolean
Returns whether this window is the window in which commands are being executed.
49 50 51 52 53 |
# File 'lib/capybara/window.rb', line 49 def current? @driver.current_window_handle == @handle rescue @driver.no_such_window_error false end |
#eql?(other) ⇒ Boolean Also known as: ==
103 104 105 |
# File 'lib/capybara/window.rb', line 103 def eql?(other) other.kind_of?(self.class) && @session == other.session && @handle == other.handle end |
#exists? ⇒ Boolean
Returns whether the window is not closed.
37 38 39 |
# File 'lib/capybara/window.rb', line 37 def exists? @driver.window_handles.include?(@handle) end |
#hash ⇒ Object
108 109 110 |
# File 'lib/capybara/window.rb', line 108 def hash @session.hash ^ @handle.hash end |
#inspect ⇒ Object
112 113 114 |
# File 'lib/capybara/window.rb', line 112 def inspect "#<Window @handle=#{@handle.inspect}>" end |
#maximize ⇒ Object
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.
99 100 101 |
# File 'lib/capybara/window.rb', line 99 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.
87 88 89 |
# File 'lib/capybara/window.rb', line 87 def resize_to(width, height) @driver.resize_window_to(handle, width, height) end |
#size ⇒ Array<(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.
76 77 78 |
# File 'lib/capybara/window.rb', line 76 def size @driver.window_size(handle) end |