Skip to content

Commit 6ccd656

Browse files
committed
rb - update w3c commands and specs for window size & position
1 parent 9a8e39a commit 6ccd656

File tree

2 files changed

+68
-65
lines changed

2 files changed

+68
-65
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,18 @@ def getCurrentWindowHandle
274274
execute :getWindowHandle
275275
end
276276

277-
# TODO - These Commands might require checking for being
278-
# current window before performing
279277
def setWindowSize(width, height, handle = :current)
278+
unless handle == :current
279+
raise Error::WebDriverError, 'Switch to desired window before changing its size'
280+
end
280281
execute :setWindowSize, {}, {:width => width,
281282
:height => height}
282283
end
283284

284285
def maximizeWindow(handle = :current)
286+
unless handle == :current
287+
raise Error::WebDriverError, 'Switch to desired window before changing its size'
288+
end
285289
execute :maximizeWindow
286290
end
287291

@@ -290,19 +294,20 @@ def fullscreenWindow
290294
end
291295

292296
def getWindowSize(handle = :current)
297+
unless handle == :current
298+
raise Error::WebDriverError, 'Switch to desired window before getting its size'
299+
end
293300
data = execute :getWindowSize
294301

295302
Dimension.new data['width'], data['height']
296303
end
297304

298-
def setWindowPosition(x, y, handle = :current)
299-
execute :setWindowPosition, :x => x, :y => y
305+
def setWindowPosition(_x, _y, _handle = nil)
306+
raise Error::WebDriverError::UnsupportedOperationError, 'The W3C standard does not currently support setting the Window Position'
300307
end
301308

302-
def getWindowPosition(handle = :current)
303-
data = execute :getWindowPosition
304-
305-
Point.new data['x'], data['y']
309+
def getWindowPosition(_handle = nil)
310+
raise Error::WebDriverError::UnsupportedOperationError, 'The W3C standard does not currently support getting the Window Position'
306311
end
307312

308313
def getScreenshot

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

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,87 +24,85 @@ module WebDriver
2424
describe Window do
2525
let(:window) { driver.manage.window }
2626

27-
compliant_on :browser => [:firefox, :chrome, :edge] do
28-
it "gets the size of the current window" do
29-
size = window.size
27+
it "gets the size of the current window" do
28+
size = window.size
3029

31-
expect(size).to be_kind_of(Dimension)
30+
expect(size).to be_kind_of(Dimension)
3231

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

37-
it "sets the size of the current window" do
38-
size = window.size
36+
it "sets the size of the current window" do
37+
size = window.size
3938

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

43-
window.size = Dimension.new(target_width, target_height)
42+
window.size = Dimension.new(target_width, target_height)
4443

45-
new_size = window.size
46-
expect(new_size.width).to eq(target_width)
47-
expect(new_size.height).to eq(target_height)
48-
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
4948

50-
# Marionette BUG -
51-
# GET /session/2146a9d2-690a-4844-a5f4-e38b02d670c3/window/:window_handle/position
52-
# did not match a known command
53-
not_compliant_on({:driver => :marionette},
54-
{:driver => :remote, :browser => :firefox, :platform => :linux}) do
55-
it "gets the position of the current window" do
56-
pos = driver.manage.window.position
49+
# Marionette BUG -
50+
# GET /session/2146a9d2-690a-4844-a5f4-e38b02d670c3/window/:window_handle/position
51+
# did not match a known command
52+
not_compliant_on({:driver => :marionette},
53+
{:driver => :remote, :browser => :firefox, :platform => :linux}) do
54+
it "gets the position of the current window" do
55+
pos = driver.manage.window.position
5756

58-
expect(pos).to be_kind_of(Point)
57+
expect(pos).to be_kind_of(Point)
5958

60-
expect(pos.x).to be >= 0
61-
expect(pos.y).to be >= 0
62-
end
59+
expect(pos.x).to be >= 0
60+
expect(pos.y).to be >= 0
6361
end
62+
end
6463

65-
not_compliant_on :driver => [:remote, :marionette], :browser => :firefox, :platform => :linux do
66-
it "sets the position of the current window" do
67-
pos = window.position
64+
not_compliant_on :driver => [:remote, :marionette], :browser => :firefox, :platform => :linux do
65+
it "sets the position of the current window" do
66+
pos = window.position
6867

69-
target_x = pos.x + 10
70-
target_y = pos.y + 10
68+
target_x = pos.x + 10
69+
target_y = pos.y + 10
7170

72-
window.position = Point.new(target_x, target_y)
71+
window.position = Point.new(target_x, target_y)
7372

74-
wait.until {window.position.x != pos.x && window.position.y != pos.y}
73+
wait.until {window.position.x != pos.x && window.position.y != pos.y}
7574

76-
new_pos = window.position
77-
expect(new_pos.x).to eq(target_x)
78-
expect(new_pos.y).to eq(target_y)
79-
end
75+
new_pos = window.position
76+
expect(new_pos.x).to eq(target_x)
77+
expect(new_pos.y).to eq(target_y)
8078
end
8179
end
80+
end
8281

83-
compliant_on({:browser => :ie},
84-
{:browser => :edge},
85-
{:browser => :firefox, :platform => [:windows, :macosx]}) do
86-
it "can maximize the current window" do
87-
window.size = old_size = Dimension.new(200, 200)
82+
compliant_on({:browser => :ie},
83+
{:browser => :edge},
84+
{:browser => :firefox, :platform => [:windows, :macosx]}) do
85+
it "can maximize the current window" do
86+
window.size = old_size = Dimension.new(200, 200)
8887

89-
window.maximize
88+
window.maximize
9089

91-
new_size = window.size
92-
expect(new_size.width).to be > old_size.width
93-
expect(new_size.height).to be > old_size.height
94-
end
90+
new_size = window.size
91+
expect(new_size.width).to be > old_size.width
92+
expect(new_size.height).to be > old_size.height
9593
end
94+
end
9695

97-
compliant_on :browser => [:marionette, :edge] do
98-
not_compliant_on :browser => [:marionette, :edge] do
99-
it "can make window full screen" do
100-
window.maximize
101-
old_size = window.size
96+
compliant_on :browser => [:marionette, :edge] do
97+
not_compliant_on :browser => [:marionette, :edge] do
98+
it "can make window full screen" do
99+
window.maximize
100+
old_size = window.size
102101

103-
window.full_screen
102+
window.full_screen
104103

105-
new_size = window.size
106-
expect(new_size.height).to be > old_size.height
107-
end
104+
new_size = window.size
105+
expect(new_size.height).to be > old_size.height
108106
end
109107
end
110108
end

0 commit comments

Comments
 (0)