Path: blob/trunk/py/selenium/webdriver/remote/mobile.py
1864 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617from .command import Command181920class _ConnectionType:21def __init__(self, mask):22self.mask = mask2324@property25def airplane_mode(self):26return self.mask % 2 == 12728@property29def wifi(self):30return (self.mask / 2) % 2 == 13132@property33def data(self):34return (self.mask / 4) > 0353637class Mobile:38ConnectionType = _ConnectionType39ALL_NETWORK = ConnectionType(6)40WIFI_NETWORK = ConnectionType(2)41DATA_NETWORK = ConnectionType(4)42AIRPLANE_MODE = ConnectionType(1)4344def __init__(self, driver):45import weakref4647self._driver = weakref.proxy(driver)4849@property50def network_connection(self):51return self.ConnectionType(self._driver.execute(Command.GET_NETWORK_CONNECTION)["value"])5253def set_network_connection(self, network):54"""Set the network connection for the remote device.5556Example of setting airplane mode::5758driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)59"""60mode = network.mask if isinstance(network, self.ConnectionType) else network61return self.ConnectionType(62self._driver.execute(63Command.SET_NETWORK_CONNECTION, {"name": "network_connection", "parameters": {"type": mode}}64)["value"]65)6667@property68def context(self):69"""Returns the current context (Native or WebView)."""70return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE)7172@context.setter73def context(self, new_context) -> None:74"""Sets the current context."""75self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context})7677@property78def contexts(self):79"""Returns a list of available contexts."""80return self._driver.execute(Command.CONTEXT_HANDLES)818283