Class: Watir::Window
- Inherits:
-
Object
- Object
- Watir::Window
- Defined in:
- lib/watir/window.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if two windows are equal.
-
#close ⇒ Object
Closes window.
-
#current? ⇒ Boolean
Returns true if window is current.
-
#exists? ⇒ Boolean
(also: #present?, #exist?)
Returns true if window exists.
-
#full_screen ⇒ Object
Make window full screen.
- #handle ⇒ Object
- #hash ⇒ Object
-
#initialize(browser, selector = {}) ⇒ Window
constructor
A new instance of Window.
- #inspect ⇒ Object
-
#maximize ⇒ Object
Maximizes window.
-
#minimize ⇒ Object
Minimize window.
-
#move_to(x_coord, y_coord) ⇒ Object
Moves window to given x and y coordinates.
-
#position ⇒ Object
Returns window position.
-
#resize_to(width, height) ⇒ Object
Resizes window to given width and height.
- #selector_string ⇒ Object private
-
#size ⇒ Object
Returns window size.
-
#title ⇒ String
Returns window title.
-
#url ⇒ String
Returns window URL.
-
#use ⇒ Object
Switches to given window and executes block, then switches back.
Methods included from Waitable
Constructor Details
#initialize(browser, selector = {}) ⇒ Window
Returns a new instance of Window.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/watir/window.rb', line 10 def initialize(browser, selector = {}) @browser = browser @driver = browser.driver @selector = selector if selector.empty? @handle = current_window elsif selector.key? :handle @handle = selector.delete :handle else types = %i[title url element] return if selector.keys.all? { |k| types.include? k } raise ArgumentError, "invalid window selector: #{selector_string}" end end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
8 9 10 |
# File 'lib/watir/window.rb', line 8 def browser @browser end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if two windows are equal.
147 148 149 150 151 |
# File 'lib/watir/window.rb', line 147 def ==(other) return false unless other.is_a?(self.class) handle == other.handle end |
#close ⇒ Object
Closes window.
174 175 176 177 |
# File 'lib/watir/window.rb', line 174 def close @browser.original_window = nil if self == @browser.original_window use { @driver.close } end |
#current? ⇒ Boolean
Returns true if window is current.
166 167 168 |
# File 'lib/watir/window.rb', line 166 def current? current_window == handle end |
#exists? ⇒ Boolean Also known as: present?, exist?
Returns true if window exists.
127 128 129 130 131 132 |
# File 'lib/watir/window.rb', line 127 def exists? assert_exists true rescue NoMatchingWindowFoundException false end |
#full_screen ⇒ Object
Make window full screen.
117 118 119 |
# File 'lib/watir/window.rb', line 117 def full_screen use { @driver.manage.window.full_screen } end |
#handle ⇒ Object
234 235 236 |
# File 'lib/watir/window.rb', line 234 def handle @handle ||= locate end |
#hash ⇒ Object
154 155 156 |
# File 'lib/watir/window.rb', line 154 def hash [handle, self.class].hash end |
#inspect ⇒ Object
27 28 29 30 |
# File 'lib/watir/window.rb', line 27 def inspect format('#<%<class>s:0x%<hash>x located=%<handle>s>', class: self.class, hash: hash * 2, handle: !!@handle) end |
#maximize ⇒ Object
Maximizes window.
95 96 97 |
# File 'lib/watir/window.rb', line 95 def maximize use { @driver.manage.window.maximize } end |
#minimize ⇒ Object
Minimize window.
106 107 108 |
# File 'lib/watir/window.rb', line 106 def minimize use { @driver.manage.window.minimize } end |
#move_to(x_coord, y_coord) ⇒ Object
Moves window to given x and y coordinates.
82 83 84 85 86 |
# File 'lib/watir/window.rb', line 82 def move_to(x_coord, y_coord) Selenium::WebDriver::Point.new(Integer(x_coord), Integer(y_coord)).tap do |point| use { @driver.manage.window.position = point } end end |
#position ⇒ Object
Returns window position.
52 53 54 |
# File 'lib/watir/window.rb', line 52 def position use { return @driver.manage.window.position } end |
#resize_to(width, height) ⇒ Object
Resizes window to given width and height.
66 67 68 69 70 |
# File 'lib/watir/window.rb', line 66 def resize_to(width, height) Selenium::WebDriver::Dimension.new(Integer(width), Integer(height)).tap do |dimension| use { @driver.manage.window.size = dimension } end end |
#selector_string ⇒ Object
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.
230 231 232 |
# File 'lib/watir/window.rb', line 230 def selector_string @selector.inspect end |
#size ⇒ Object
Returns window size.
40 41 42 |
# File 'lib/watir/window.rb', line 40 def size use { return @driver.manage.window.size } end |
#title ⇒ String
Returns window title.
185 186 187 |
# File 'lib/watir/window.rb', line 185 def title use { return @driver.title } end |
#url ⇒ String
Returns window URL.
195 196 197 |
# File 'lib/watir/window.rb', line 195 def url use { return @driver.current_url } end |
#use ⇒ Object
Switches to given window and executes block, then switches back.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/watir/window.rb', line 208 def use wait_for_exists cache_current = current_window @browser.original_window ||= cache_current restore_to = unless cache_current == handle @driver.switch_to.window(handle) cache_current end if block_given? begin yield ensure @driver.switch_to.window(restore_to) if restore_to end end self end |