Skip to content

Commit

Permalink
adding context switching for mobile to python
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis committed Feb 28, 2015
1 parent 590e493 commit 17872d6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions py/selenium/webdriver/remote/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ class Command(object):
GET_APP_CACHE_STATUS = "getAppCacheStatus"
CLEAR_APP_CACHE = "clearAppCache"

GET_NETWORK_CONNECTION = "getNetworkConnection"
SET_NETWORK_CONNECTION = "setNetworkConnection"

GET_LOCAL_STORAGE_ITEM = "getLocalStorageItem"
REMOVE_LOCAL_STORAGE_ITEM = "removeLocalStorageItem"
GET_LOCAL_STORAGE_KEYS = "getLocalStorageKeys"
Expand All @@ -141,3 +138,10 @@ class Command(object):
SET_SESSION_STORAGE_ITEM = "setSessionStorageItem"
CLEAR_SESSION_STORAGE = "clearSessionStorage"
GET_SESSION_STORAGE_SIZE = "getSessionStorageSize"

# Mobile
GET_NETWORK_CONNECTION = "getNetworkConnection"
SET_NETWORK_CONNECTION = "setNetworkConnection"
CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle"
CONTEXT_HANDLES = "getContextHandles"
SWITCH_TO_CONTEXT = "switchToContext"
20 changes: 20 additions & 0 deletions py/selenium/webdriver/remote/mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,23 @@ def set_network_connection(self, network):
return self.ConnectionType(self._driver.execute(Command.SET_NETWORK_CONNECTION,
{'name':'network_connection',
'parameters':{'type': mode}})['value'])
@property
def context(self):
"""
returns the current context (Native or WebView).
"""
return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE)

@property
def contexts(self):
"""
returns a list of available contexts
"""
return self._driver.execute(Command.CONTEXT_HANDLES)

@context.setter
def context(self, new_context):
"""
sets the current context
"""
self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context})
6 changes: 6 additions & 0 deletions py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ def __init__(self, remote_server_addr, keep_alive=False):
('POST', '/session/$sessionId/log'),
Command.GET_AVAILABLE_LOG_TYPES:
('GET', '/session/$sessionId/log/types'),
Command.CURRENT_CONTEXT_HANDLE:
('GET', '/session/$sessionId/context'),
Command.CONTEXT_HANDLES:
('GET', '/session/$sessionId/contexts'),
Command.SWITCH_TO_CONTEXT:
('POST', '/session/$sessionId/context'),
}

def execute(self, command, params):
Expand Down

0 comments on commit 17872d6

Please sign in to comment.