Class: Watir::Window
- Inherits:
-
Object
- Object
- Watir::Window
- Includes:
- EventuallyPresent
- Defined in:
- lib/watir-webdriver/window.rb
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.
- #hash ⇒ Object
-
#initialize(driver, selector) ⇒ Window
constructor
A new instance of Window.
- #inspect ⇒ Object
-
#maximize ⇒ Object
Maximizes window.
-
#move_to(x, y) ⇒ 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.
-
#size ⇒ Object
Returns window size.
-
#title ⇒ String
Returns window title.
-
#url ⇒ String
Returns window URL.
-
#use(&blk) ⇒ Object
Switches to given window and executes block, then switches back.
Methods included from EventuallyPresent
#wait_until_present, #wait_while_present, #when_present
Constructor Details
#initialize(driver, selector) ⇒ Window
Returns a new instance of Window.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/watir-webdriver/window.rb', line 5 def initialize(driver, selector) @driver = driver @selector = selector if selector.empty? @handle = current_window elsif selector.has_key? :handle @handle = selector.delete :handle else unless selector.keys.all? { |k| [:title, :url, :index].include? k } raise ArgumentError, "invalid window selector: #{selector.inspect}" end end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if two windows are equal.
125 126 127 128 129 |
# File 'lib/watir-webdriver/window.rb', line 125 def ==(other) return false unless other.kind_of?(self.class) handle == other.handle end |
#close ⇒ Object
Closes window.
152 153 154 |
# File 'lib/watir-webdriver/window.rb', line 152 def close use { @driver.close } end |
#current? ⇒ Boolean
Returns true if window is current.
144 145 146 |
# File 'lib/watir-webdriver/window.rb', line 144 def current? current_window == handle end |
#exists? ⇒ Boolean Also known as: present?, exist?
Returns true if window exists.
105 106 107 108 109 110 |
# File 'lib/watir-webdriver/window.rb', line 105 def exists? assert_exists true rescue Exception::NoMatchingWindowFoundException false end |
#hash ⇒ Object
132 133 134 |
# File 'lib/watir-webdriver/window.rb', line 132 def hash handle.hash ^ self.class.hash end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/watir-webdriver/window.rb', line 20 def inspect '#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle] end |
#maximize ⇒ Object
Maximizes window.
95 96 97 |
# File 'lib/watir-webdriver/window.rb', line 95 def maximize use { @driver.manage.window.maximize } end |
#move_to(x, y) ⇒ Object
Moves window to given x and y coordinates.
81 82 83 84 85 86 |
# File 'lib/watir-webdriver/window.rb', line 81 def move_to(x, y) point = Selenium::WebDriver::Point.new(Integer(x), Integer(y)) use { @driver.manage.window.position = point } point end |
#position ⇒ Object
Returns window position.
47 48 49 50 51 52 |
# File 'lib/watir-webdriver/window.rb', line 47 def position pos = nil use { pos = @driver.manage.window.position } pos end |
#resize_to(width, height) ⇒ Object
Resizes window to given width and height.
64 65 66 67 68 69 |
# File 'lib/watir-webdriver/window.rb', line 64 def resize_to(width, height) dimension = Selenium::WebDriver::Dimension.new(Integer(width), Integer(height)) use { @driver.manage.window.size = dimension } dimension end |
#size ⇒ Object
Returns window size.
32 33 34 35 36 37 |
# File 'lib/watir-webdriver/window.rb', line 32 def size size = nil use { size = @driver.manage.window.size } size end |
#title ⇒ String
Returns window title.
162 163 164 165 166 167 |
# File 'lib/watir-webdriver/window.rb', line 162 def title title = nil use { title = @driver.title } title end |
#url ⇒ String
Returns window URL.
175 176 177 178 179 180 |
# File 'lib/watir-webdriver/window.rb', line 175 def url url = nil use { url = @driver.current_url } url end |
#use(&blk) ⇒ Object
Switches to given window and executes block, then switches back.
191 192 193 194 195 |
# File 'lib/watir-webdriver/window.rb', line 191 def use(&blk) assert_exists @driver.switch_to.window(handle, &blk) self end |