Skip to content

Commit a0f75c2

Browse files
committed
[rb] use rect for firefox with support for previous geckodriver versions
add specs for window rect and minimize
1 parent 69be61e commit a0f75c2

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

rb/lib/selenium/webdriver/firefox/w3c_bridge.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,33 @@ def quit
6060
@service.stop if @service
6161
end
6262

63-
# Firefox doesn't implement rect yet
63+
# Support for geckodriver < 0.15
6464
def resize_window(width, height, handle = :current)
65-
unless handle == :current
66-
raise Error::WebDriverError, 'Switch to desired window before changing its size'
67-
end
65+
super
66+
rescue Error::UnknownCommandError
6867
execute :set_window_size, {}, {width: width, height: height}
6968
end
7069

7170
def window_size(handle = :current)
72-
unless handle == :current
73-
raise Error::UnsupportedOperationError, 'Switch to desired window before getting its size'
74-
end
71+
data = super
72+
rescue Error::UnknownCommandError
7573
data = execute :get_window_size
76-
77-
Dimension.new data['width'], data['height']
74+
ensure
75+
return Dimension.new data['width'], data['height']
7876
end
7977

8078
def reposition_window(x, y)
79+
super
80+
rescue Error::UnknownCommandError
8181
execute :set_window_position, {}, {x: x, y: y}
8282
end
8383

8484
def window_position
85+
data = super
86+
rescue Error::UnknownCommandError
8587
data = execute :get_window_position
86-
Point.new data['x'], data['y']
88+
ensure
89+
return Point.new data['x'], data['y']
8790
end
8891

8992
private

rb/lib/selenium/webdriver/remote/w3c_bridge.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ def window_position
270270
Point.new data['x'], data['y']
271271
end
272272

273-
def set_window_rect(width: nil, height: nil, x: nil, y: nil)
274-
execute :set_window_rect, {}, {width: width, height: height, x: x, y: y}
273+
def set_window_rect(x: nil, y: nil, width: nil, height: nil)
274+
execute :set_window_rect, {}, {x: x, y: y, width: width, height: height}
275275
end
276276

277277
def window_rect

rb/spec/integration/selenium/webdriver/window_spec.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,42 @@ module WebDriver
7474
end
7575
end
7676

77+
compliant_on browser: :ff_nightly do
78+
it 'gets the rect of the current window' do
79+
rect = driver.manage.window.rect
80+
81+
expect(rect).to be_a(Rectangle)
82+
83+
expect(rect.x).to be >= 0
84+
expect(rect.y).to be >= 0
85+
expect(rect.width).to be >= 0
86+
expect(rect.height).to be >= 0
87+
end
88+
89+
it 'sets the rect of the current window' do
90+
rect = window.rect
91+
92+
target_x = rect.x + 10
93+
target_y = rect.y + 10
94+
target_width = rect.width + 10
95+
target_height = rect.height + 10
96+
97+
window.rect = Rectangle.new(target_x, target_y, target_width, target_height)
98+
99+
wait.until { window.rect.x != rect.x && window.rect.y != rect.y }
100+
101+
new_rect = window.rect
102+
expect(new_rect.x).to eq(target_x)
103+
expect(new_rect.y).to eq(target_y)
104+
expect(new_rect.width).to eq(target_width)
105+
expect(new_rect.height).to eq(target_height)
106+
end
107+
end
108+
77109
# TODO: - Create Window Manager guard
78110
not_compliant_on platform: :linux do
79111
not_compliant_on browser: :safari do
80-
it 'can maximize the current window' do
112+
it 'can maximize the current window' do
81113
window.size = old_size = Dimension.new(200, 200)
82114

83115
window.maximize
@@ -87,7 +119,7 @@ module WebDriver
87119
new_size = window.size
88120
expect(new_size.width).to be > old_size.width
89121
expect(new_size.height).to be > old_size.height
90-
end
122+
end
91123
end
92124
end
93125

@@ -106,6 +138,18 @@ module WebDriver
106138
end
107139
end
108140
end
141+
142+
compliant_on browser: [:ff_nightly, :firefox, :edge] do
143+
# Firefox - Not implemented yet, no bug to track
144+
# Edge: Not Yet - https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
145+
not_compliant_on browser: [:ff_nightly, :firefox, :edge] do
146+
it 'can minimize the window' do
147+
driver.execute_script('window.minimized = false; window.onblur = function(){ window.minimized = true };')
148+
window.minimize
149+
expect(driver.execute_script('return window.minimized;')).to be true
150+
end
151+
end
152+
end
109153
end
110154
end # WebDriver
111155
end # Selenium

0 commit comments

Comments
 (0)