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
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.
-
#present? ⇒ Boolean
Returns true if window is present.
-
#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 = driver.window_handle 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.
133 134 135 136 137 |
# File 'lib/watir-webdriver/window.rb', line 133 def ==(other) return false unless other.kind_of?(self.class) handle == other.handle end |
#close ⇒ Object
CLoses window.
160 161 162 |
# File 'lib/watir-webdriver/window.rb', line 160 def close use { @driver.close } end |
#current? ⇒ Boolean
Returns true if window is current.
152 153 154 |
# File 'lib/watir-webdriver/window.rb', line 152 def current? @driver.window_handle == handle end |
#exists? ⇒ Boolean
Returns true if window exists.
105 106 107 108 109 110 |
# File 'lib/watir-webdriver/window.rb', line 105 def exists? handle true rescue Exception::NoMatchingWindowFoundException false end |
#hash ⇒ Object
140 141 142 |
# File 'lib/watir-webdriver/window.rb', line 140 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 |
#present? ⇒ Boolean
Returns true if window is present.
118 119 120 121 122 |
# File 'lib/watir-webdriver/window.rb', line 118 def present? @handle = nil # relocate exists? 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.
170 171 172 173 174 175 |
# File 'lib/watir-webdriver/window.rb', line 170 def title title = nil use { title = @driver.title } title end |
#url ⇒ String
Returns window URL.
183 184 185 186 187 188 |
# File 'lib/watir-webdriver/window.rb', line 183 def url url = nil use { url = @driver.current_url } url end |
#use(&blk) ⇒ Object
Switches to given window and executes block, then switches back.
199 200 201 202 |
# File 'lib/watir-webdriver/window.rb', line 199 def use(&blk) @driver.switch_to.window(handle, &blk) self end |