Skip to content

Commit e3645a4

Browse files
committed
[rb] implement window position for w3c
1 parent 6481e7b commit e3645a4

3 files changed

Lines changed: 61 additions & 63 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@ def window_size(handle = :current)
254254
Dimension.new data['width'], data['height']
255255
end
256256

257-
def reposition_window(_x, _y, _handle = nil)
258-
raise Error::UnsupportedOperationError, 'The W3C standard does not currently support setting the Window Position'
257+
def reposition_window(x, y)
258+
execute :set_window_position, {}, {x: x, y: y}
259259
end
260260

261-
def window_position(_handle = nil)
262-
raise Error::UnsupportedOperationError, 'The W3C standard does not currently support getting the Window Position'
261+
def window_position
262+
data = execute :get_window_position
263+
Point.new data['x'], data['y']
263264
end
264265

265266
def screenshot

rb/lib/selenium/webdriver/remote/w3c_commands.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class W3CBridge
5757
maximize_window: [:post, 'session/:session_id/window/maximize'.freeze],
5858
set_window_size: [:post, 'session/:session_id/window/size'.freeze],
5959
get_window_size: [:get, 'session/:session_id/window/size'.freeze],
60+
set_window_position: [:post, 'session/:session_id/window/position'.freeze],
61+
get_window_position: [:get, 'session/:session_id/window/position'.freeze],
6062
switch_to_frame: [:post, 'session/:session_id/frame'.freeze],
6163
switch_to_parent_frame: [:post, 'session/:session_id/frame/parent'.freeze],
6264

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

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,89 +21,84 @@
2121

2222
module Selenium
2323
module WebDriver
24-
# Remote w3c bug: https://github.com/SeleniumHQ/selenium/issues/2856
25-
not_compliant_on driver: :remote, browser: :firefox do
26-
describe Window do
27-
let(:window) { driver.manage.window }
24+
describe Window do
25+
let(:window) { driver.manage.window }
2826

29-
it 'gets the size of the current window' do
30-
size = window.size
27+
it 'gets the size of the current window' do
28+
size = window.size
3129

32-
expect(size).to be_kind_of(Dimension)
30+
expect(size).to be_a(Dimension)
3331

34-
expect(size.width).to be > 0
35-
expect(size.height).to be > 0
36-
end
32+
expect(size.width).to be > 0
33+
expect(size.height).to be > 0
34+
end
3735

38-
it 'sets the size of the current window' do
39-
size = window.size
36+
it 'sets the size of the current window' do
37+
size = window.size
4038

41-
target_width = size.width - 20
42-
target_height = size.height - 20
39+
target_width = size.width - 20
40+
target_height = size.height - 20
4341

44-
window.size = Dimension.new(target_width, target_height)
42+
window.size = Dimension.new(target_width, target_height)
4543

46-
new_size = window.size
47-
expect(new_size.width).to eq(target_width)
48-
expect(new_size.height).to eq(target_height)
49-
end
44+
new_size = window.size
45+
expect(new_size.width).to eq(target_width)
46+
expect(new_size.height).to eq(target_height)
47+
end
5048

51-
not_compliant_on browser: :firefox do
52-
it 'gets the position of the current window' do
53-
pos = driver.manage.window.position
49+
it 'gets the position of the current window' do
50+
pos = driver.manage.window.position
5451

55-
expect(pos).to be_kind_of(Point)
52+
expect(pos).to be_a(Point)
5653

57-
expect(pos.x).to be >= 0
58-
expect(pos.y).to be >= 0
59-
end
60-
end
54+
expect(pos.x).to be >= 0
55+
expect(pos.y).to be >= 0
56+
end
6157

62-
not_compliant_on browser: [:phantomjs, :firefox] do
63-
it 'sets the position of the current window' do
64-
pos = window.position
58+
not_compliant_on browser: :phantomjs do
59+
it 'sets the position of the current window' do
60+
pos = window.position
6561

66-
target_x = pos.x + 10
67-
target_y = pos.y + 10
62+
target_x = pos.x + 10
63+
target_y = pos.y + 10
6864

69-
window.position = Point.new(target_x, target_y)
65+
window.position = Point.new(target_x, target_y)
7066

71-
wait.until { window.position.x != pos.x && window.position.y != pos.y }
67+
wait.until { window.position.x != pos.x && window.position.y != pos.y }
7268

73-
new_pos = window.position
74-
expect(new_pos.x).to eq(target_x)
75-
expect(new_pos.y).to eq(target_y)
76-
end
69+
new_pos = window.position
70+
expect(new_pos.x).to eq(target_x)
71+
expect(new_pos.y).to eq(target_y)
7772
end
73+
end
7874

79-
# TODO: - Create Window Manager guard
80-
not_compliant_on platform: :linux do
81-
it 'can maximize the current window' do
82-
window.size = old_size = Dimension.new(200, 200)
75+
# TODO: - Create Window Manager guard
76+
not_compliant_on platform: :linux do
77+
it 'can maximize the current window' do
78+
window.size = old_size = Dimension.new(200, 200)
8379

84-
window.maximize
80+
window.maximize
8581

86-
wait.until { window.size != old_size }
82+
wait.until { window.size != old_size }
8783

88-
new_size = window.size
89-
expect(new_size.width).to be > old_size.width
90-
expect(new_size.height).to be > old_size.height
91-
end
84+
new_size = window.size
85+
expect(new_size.width).to be > old_size.width
86+
expect(new_size.height).to be > old_size.height
9287
end
88+
end
9389

94-
compliant_on browser: [:firefox, :edge] do
95-
# Firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1189749
96-
# Edge: Not Yet - https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
97-
not_compliant_on browser: [:firefox, :edge] do
98-
it 'can make window full screen' do
99-
window.maximize
100-
old_size = window.size
90+
compliant_on browser: [:firefox, :edge] do
91+
# Firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1189749
92+
# Edge: Not Yet - https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
93+
not_compliant_on browser: [:firefox, :edge] do
94+
it 'can make window full screen' do
95+
window.maximize
96+
old_size = window.size
10197

102-
window.full_screen
98+
window.full_screen
10399

104-
new_size = window.size
105-
expect(new_size.height).to be > old_size.height
106-
end
100+
new_size = window.size
101+
expect(new_size.height).to be > old_size.height
107102
end
108103
end
109104
end

0 commit comments

Comments
 (0)