Skip to content

Commit 3dad4a8

Browse files
author
AutomatedTester
committed
Add the ability to handle windows with the W3C Dialect of the JSON Protocol
1 parent 3cebf74 commit 3dad4a8

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

Diff for: py/selenium/webdriver/remote/command.py

+3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ class Command(object):
5757
GET_CURRENT_WINDOW_HANDLE = "getCurrentWindowHandle"
5858
GET_WINDOW_HANDLES = "getWindowHandles"
5959
GET_WINDOW_SIZE = "getWindowSize"
60+
W3C_GET_WINDOW_SIZE = "w3cGetWindowSize"
6061
GET_WINDOW_POSITION = "getWindowPosition"
6162
SET_WINDOW_SIZE = "setWindowSize"
63+
W3C_SET_WINDOW_SIZE = "w3cSetWindowSize"
6264
SET_WINDOW_POSITION = "setWindowPosition"
6365
SWITCH_TO_WINDOW = "switchToWindow"
6466
SWITCH_TO_FRAME = "switchToFrame"
@@ -89,6 +91,7 @@ class Command(object):
8991
SET_SCRIPT_TIMEOUT = "setScriptTimeout"
9092
SET_TIMEOUTS = "setTimeouts"
9193
MAXIMIZE_WINDOW = "windowMaximize"
94+
W3C_MAXIMIZE_WINDOW = "w3cMaximizeWindow"
9295
GET_LOG = "getLog"
9396
GET_AVAILABLE_LOG_TYPES = "getAvailableLogTypes"
9497

Diff for: py/selenium/webdriver/remote/remote_connection.py

+6
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,20 @@ def __init__(self, remote_server_addr, keep_alive=False):
289289
('POST', '/session/$sessionId/moveto'),
290290
Command.GET_WINDOW_SIZE:
291291
('GET', '/session/$sessionId/window/$windowHandle/size'),
292+
Command.W3C_GET_WINDOW_SIZE:
293+
('GET', '/session/$sessionId/window/size'),
292294
Command.SET_WINDOW_SIZE:
293295
('POST', '/session/$sessionId/window/$windowHandle/size'),
296+
Command.W3C_SET_WINDOW_SIZE:
297+
('POST', '/session/$sessionId/window/size'),
294298
Command.GET_WINDOW_POSITION:
295299
('GET', '/session/$sessionId/window/$windowHandle/position'),
296300
Command.SET_WINDOW_POSITION:
297301
('POST', '/session/$sessionId/window/$windowHandle/position'),
298302
Command.MAXIMIZE_WINDOW:
299303
('POST', '/session/$sessionId/window/$windowHandle/maximize'),
304+
Command.W3C_MAXIMIZE_WINDOW:
305+
('POST', '/session/$sessionId/window/maximize'),
300306
Command.SET_SCREEN_ORIENTATION:
301307
('POST', '/session/$sessionId/orientation'),
302308
Command.GET_SCREEN_ORIENTATION:

Diff for: py/selenium/webdriver/remote/switch_to.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,7 @@ def window(self, window_name):
8686
:Usage:
8787
driver.switch_to.window('main')
8888
"""
89-
self._driver.execute(Command.SWITCH_TO_WINDOW, {'name': window_name})
89+
data = {'name': window_name}
90+
if self._driver.capabilities['marionette'] == True:
91+
data = {'handle': window_name}
92+
self._driver.execute(Command.SWITCH_TO_WINDOW, data)

Diff for: py/selenium/webdriver/remote/webdriver.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def start_session(self, desired_capabilities, browser_profile=None):
138138
self.session_id = response['sessionId']
139139
self.capabilities = response['value']
140140

141+
self.capabilities["marionette"] = desired_capabilities.get("marionette", False)
142+
141143
def _wrap_value(self, value):
142144
if isinstance(value, dict):
143145
converted = {}
@@ -500,7 +502,10 @@ def maximize_window(self):
500502
"""
501503
Maximizes the current window that webdriver is using
502504
"""
503-
self.execute(Command.MAXIMIZE_WINDOW, {"windowHandle": "current"})
505+
command = Command.MAXIMIZE_WINDOW
506+
if self.capabilities['marionette'] == True:
507+
command = Command.W3C_MAXIMIZE_WINDOW
508+
self.execute(command, {"windowHandle": "current"})
504509

505510
@property
506511
def switch_to(self):
@@ -777,7 +782,10 @@ def set_window_size(self, width, height, windowHandle='current'):
777782
:Usage:
778783
driver.set_window_size(800,600)
779784
"""
780-
self.execute(Command.SET_WINDOW_SIZE, {'width': int(width), 'height': int(height),
785+
command = Command.SET_WINDOW_SIZE
786+
if self.capabilities["marionette"] == True:
787+
command = Command.W3C_SET_WINDOW_SIZE
788+
self.execute(command, {'width': int(width), 'height': int(height),
781789
'windowHandle': windowHandle})
782790

783791
def get_window_size(self, windowHandle='current'):
@@ -787,8 +795,16 @@ def get_window_size(self, windowHandle='current'):
787795
:Usage:
788796
driver.get_window_size()
789797
"""
790-
return self.execute(Command.GET_WINDOW_SIZE,
791-
{'windowHandle': windowHandle})['value']
798+
command = Command.GET_WINDOW_SIZE
799+
if self.capabilities['marionette'] == True:
800+
command = Command.W3C_GET_WINDOW_SIZE
801+
size = self.execute(command,
802+
{'windowHandle': windowHandle})
803+
804+
if size.get('value', None) != None:
805+
return size['value']
806+
else:
807+
return size
792808

793809
def set_window_position(self, x, y, windowHandle='current'):
794810
"""

0 commit comments

Comments
 (0)