Skip to content

Commit 17872d6

Browse files
committed
adding context switching for mobile to python
1 parent 590e493 commit 17872d6

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ class Command(object):
125125
GET_APP_CACHE_STATUS = "getAppCacheStatus"
126126
CLEAR_APP_CACHE = "clearAppCache"
127127

128-
GET_NETWORK_CONNECTION = "getNetworkConnection"
129-
SET_NETWORK_CONNECTION = "setNetworkConnection"
130-
131128
GET_LOCAL_STORAGE_ITEM = "getLocalStorageItem"
132129
REMOVE_LOCAL_STORAGE_ITEM = "removeLocalStorageItem"
133130
GET_LOCAL_STORAGE_KEYS = "getLocalStorageKeys"
@@ -141,3 +138,10 @@ class Command(object):
141138
SET_SESSION_STORAGE_ITEM = "setSessionStorageItem"
142139
CLEAR_SESSION_STORAGE = "clearSessionStorage"
143140
GET_SESSION_STORAGE_SIZE = "getSessionStorageSize"
141+
142+
# Mobile
143+
GET_NETWORK_CONNECTION = "getNetworkConnection"
144+
SET_NETWORK_CONNECTION = "setNetworkConnection"
145+
CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle"
146+
CONTEXT_HANDLES = "getContextHandles"
147+
SWITCH_TO_CONTEXT = "switchToContext"

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

+20
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,23 @@ def set_network_connection(self, network):
5252
return self.ConnectionType(self._driver.execute(Command.SET_NETWORK_CONNECTION,
5353
{'name':'network_connection',
5454
'parameters':{'type': mode}})['value'])
55+
@property
56+
def context(self):
57+
"""
58+
returns the current context (Native or WebView).
59+
"""
60+
return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE)
61+
62+
@property
63+
def contexts(self):
64+
"""
65+
returns a list of available contexts
66+
"""
67+
return self._driver.execute(Command.CONTEXT_HANDLES)
68+
69+
@context.setter
70+
def context(self, new_context):
71+
"""
72+
sets the current context
73+
"""
74+
self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context})

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

+6
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ def __init__(self, remote_server_addr, keep_alive=False):
327327
('POST', '/session/$sessionId/log'),
328328
Command.GET_AVAILABLE_LOG_TYPES:
329329
('GET', '/session/$sessionId/log/types'),
330+
Command.CURRENT_CONTEXT_HANDLE:
331+
('GET', '/session/$sessionId/context'),
332+
Command.CONTEXT_HANDLES:
333+
('GET', '/session/$sessionId/contexts'),
334+
Command.SWITCH_TO_CONTEXT:
335+
('POST', '/session/$sessionId/context'),
330336
}
331337

332338
def execute(self, command, params):

0 commit comments

Comments
 (0)